简体   繁体   English

Lombok不生成RequiredArgsConstructor和AllArgsConstructor

[英]Lombok does not generate RequiredArgsConstructor and AllArgsConstructor

I am using Lombok 1.16.18 and Gradle 4.0 with Java 8 and Spring-Boot 1.5.9.RELEASE. 我使用的是Lombok 1.16.18和Gradle 4.0,Java 8和Spring-Boot 1.5.9.RELEASE。

When I build and run the project it succeeds, but when calling services which include Autowiring it fails with NullPointerException using @RequiredArgsConstructor(onConstructor = @__(@Autowired)) or @AllArgsConstructor(onConstructor = @__(@Autowired)) . 当我构建并运行项目时,它成功,但是当调用包含自动装配的服务时,使用@RequiredArgsConstructor(onConstructor = @__(@Autowired))@AllArgsConstructor(onConstructor = @__(@Autowired))使用NullPointerException失败。

I have checked the generated .classes and they are missing the constructors. 我检查了生成的.classes,他们缺少构造函数。

Of course if I create the constructors by hand and put @Autowire on it it works. 当然,如果我手工创建构造函数并将@Autowire放在其上就可以了。 But I am working on a big project with a lot of existing code, and don't want to rewrite everything. 但我正在开发一个包含大量现有代码的大项目,并且不想重写所有内容。 Any ideas on why this could happen? 为什么会发生这种情况的任何想法? It looks like gradle or lombok is not preprocessing these annotations, however all the other @Getter and @Setter etc. are working fine and the generated .class files contain them... 它看起来像gradle或lombok没有预处理这些注释,但所有其他@Getter@Setter等工作正常,生成的.class文件包含它们......

I use constructor injection only defining @RequiredArgsConstructor with final member variables as follows (without using onConstructor ) 我使用构造函数注入只定义@RequiredArgsConstructorfinal成员变量,如下所示(不使用onConstructor

@Repository
@Slf4j
@RequiredArgsConstructor
public class FieldRepository {

    private final DSLContext dsl;

    private final DataSource dataSource;

    //... dsl and datasource are correctly injected 

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM