Lombok在spring中的特殊注解@RequiredArgsConstructor
在了解lombok中的特殊注解之前:了解一下spring的常用注入方式
戳这里
1.注解注入:
Controller
public class FooController {
@Autowired
//@Inject
private FooService fooService;
//简单的使用例子,下同
public List<Foo> listFoo() {
return fooService.list();
}
}
2.构造器注入:
Controller
public class FooController {
private final FooService fooService;
@Autowired
public FooController(FooService fooService) {
this.fooService = fooService;
}
//使用方式上同,略
}
3.setter注入:
@Controller
public class FooController {
private FooService fooService;
//使用方式上同,略
@Autowired
public void setFooService(FooService fooService) {
this.fooService = fooService;
}
}
最后就是lombok中的@RequiredArgsConstructor
@RequiredArgsConstructor
public class VerifyController {
private final VerifyService verifyService;
private final InvitationService invitationService;
private final VerificationCodeService verificationCodeService;
版权声明:本文为qq_51705526原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。