I have a class like this:
@Service("aSpringService")
@RequiredArgsConstructor(onConstructor = @__({@Autowired}))
public class ServiceImpl implements Service {
@NonNull
private final Member1 m1;
@NonNull
private final Member2 m2;
@NonNull
private final Member3 m3;
}
The constructor will be created by Lombok and at runtime, spring will inject the members into the constructor. Now I need a setup-method and got stuck with lombok. It seems, that Lombok cannot call something self-written.
What I want
I want a new parameter for the Lombok-Annotation like useDefaultConstructor. When this parameter is present, then the automated-code (from Lombok) will call a parameter-less constructor, which I can write for my own.
@RequiredArgsConstructor(onConstructor = @__({@Autowired}), useDefaultConstructor = true)
// Note the "useDefaultConstructor = true"
public class ServiceImpl implements Service {
@NonNull
private final Member1 m1;
private ServiceImpl() {
//some self-written setup-code
}
}
Generated class:
public class ServiceImpl implements Service {
private final Member1 m1;
// This constructor is not generated by lombok
private ServiceImpl() {
//some self-written setup-code
}
// Constructor generated by lombok
@Autowired
public ServiceImpl(Member1 m1) {
this(); // <- only created when "useDefaultConstructor" is present
this.m1 = m1;
}
}
The question
Is there a way to do this with lombok? Iam to lazy to write the constructor for my own (and change it everytime, when a need a new spring-member).