简体   繁体   中英

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.

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)) .

I have checked the generated .classes and they are missing the constructors.

Of course if I create the constructors by hand and put @Autowire on it it works. 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...

I use constructor injection only defining @RequiredArgsConstructor with final member variables as follows (without using onConstructor )

@Repository
@Slf4j
@RequiredArgsConstructor
public class FieldRepository {

    private final DSLContext dsl;

    private final DataSource dataSource;

    //... dsl and datasource are correctly injected 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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