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;
到此这篇关于spring中的特殊注解@RequiredArgsConstructor的文章就介绍到这了,更多相关spring注解@RequiredArgsConstructor内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!