Reputation: 2395
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...
Upvotes: 6
Views: 8919
Reputation: 3166
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
}
Upvotes: 10