描述:@RequiredArgsConstructor注解是lombok包下的,用于让spring完成bean自动装配的工作。
用法:标注在类上,可以省略@Autowired注解,但是一定要加final修饰符否则注入失败。
@RequiredArgsConstructor
问:@AllArgsConstructor和@RequiredArgsConstructor区别?
答:以上两个注解都是通过自动生成构造函数注入bean,区别就在于@AllArgsConstructor会将类中所有的属性都生成构造函数,而@RequiredArgsConstructor只会生成final修饰的字段。