Is it possible to call a specific initialization method right after calling the constructor using annotations from javax?
I put the @Inject annotation (javax.inject.Inject) over the field that I want to initialize in the method with the @PostConstruct annotation (javax.annotation.PostConstruct) right after the constructor is called, but this init method is not called and NPE crashes.
public class ClassChild extends ClassParent{
@Inject
private SomeService someService;
@PostConstruct
public void init(){
someService = new SomeService(getSomeValues()) // getSomeValues() a method from parent
}
Am I using these annotations correctly? What is the problem? How to call the init() method right after calling the ClassChild constructor? I would be very grateful for any help!
@PostConstructto initializesomeService, which should be injected. - KayamanSomeServicein this case) which is actually meant to be injected/autowired? Also, a method annotated with@PostConstructis generally used to consume the injected bean or do whatever after this bean is ready. - Isank