使用lombok 之前
@Service("customer")
@Slf4j
public class CustomerService {
@Qualifier("curtaoRestClient")
private final RestHighLevelClient restClient;
private final ConstructorEsUtil constructorEsUtil;
private final RequestFunction requestFunction;
private final ConfService confService;
@Autowired
public CustomerService(@Qualifier("devRestClient") RestHighLevelClient restClient,
ConstructorEsUtil constructorEsUtil, RequestFunction requestFunction, ConfService confService) {
this.restClient = restClient;
this.constructorEsUtil = constructorEsUtil;
this.requestFunction = requestFunction;
this.confService= confService;
}
使用lombok
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerService {
@Qualifier(“devRestClient”)
private final RestHighLevelClient restClient;
private final ConstructorEsUtil constructorEsUtil;
private final RequestFunction requestFunction;
private final RealmConfService realmConfService;
}
由于支持 @Qualifier注解,需要在项目的根路径中加入配置:lombok.config
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier
总结
lombok 更多新特点可以参考官方文档,在涉及反射的地方使用lombok必须要谨慎,以免与lombok产生冲突,导致反射不生效。