Spring通过lombok+构造方法注入

Spring推荐构造器注入以实现不可变对象并保证依赖非空。lombok的@RequiredArgsConstructor注解能自动生成包含非空final字段的构造器,帮助实现初始化。
摘要由CSDN通过智能技术生成

Spring通过lombok+构造方法注入

The Spring team generally advocates constructor injection as it enables one to implement application components as immutable objects and to ensure that required dependencies are not null. Furthermore constructor-injected components are always returned to client (calling) code in a fully initialized state.

Spring团队通常提倡构造函数注入,因为它使人们能够将应用程序组件实现为不可变对象,并确保所需的依赖项不为空。而且,构造函数注入的组件总是以完全初始化的状态返回给客户端(调用)代码。

lombok的一个注解
@RequiredArgsConstructor:生成包含final和@NonNull注解的成员变量的构造器;

@RequiredArgsConstructor
@Service("service")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值