Lombok supports to generate constructors with @Inject annotations:
@RequiredArgsConstructor(onConstructor = @__(@Inject))
So, instead of
@Service
public class FooService {
private final BarService barService;
@Inject
public FooService(BarService barService) {
this.barService = barService;
}
}
you can write
@Service
@RequiredArgsConstructor(onConstructor = @__(@Inject))
public class FooService {
private final BarService barService;
}
My problem with that feature is that it seems to break Spring IDE support in IntelliJ:
BarService).If I was the only developer, I would just use the first version and be done with it. However, I see that more and more code in our codebase is migrated to the Lombok constructor style. So, I am curious:
Is it possible to use the full Spring support in IDEA in combination with Lombok onConstructor = @__(@Inject) constructors?
The lombok annotation @RequiredArgsConstructor will do the constructor based dependency injection.
@Service
@RequiredArgsConstructor
public class FooService {
private final BarService barService;
}
After Java 17 record will also do this like -
@Service
public record FooService(BarService barService) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With