I have a bean having:
void initialize()method annotated with@PostConstruct.void release()method annotated with@PreDestroy.- Some other methods.
- In addition that bean has a
@Interceptorsannotation defining some interceptors.
One of those interceptors has methods annotated with
@AroundConstruct@AroundInvoke@AroundTimeout@PostConstruct@PreDestroy
In each of those methods I put some logging, so I can see which and when the interceptor methods are called. And the call order looks like this:
- Interceptor's
@AroundConstructmethod is entered. InvocationContext: Target isnull, method isnull, constructor is set. - Beans constructor is called.
- The call exists through Interceptor's
@AroundConstructmethod. InvocationContext: Target is the bean instance, method isnull, constructor is set. - Interceptor's
@PostConstructmethod is called, calls proceed() and returns. InvocationContext: Target is the bean instance, method isnull, constructor is set. - After the previous call returned completely the bean's
@PostConstructmethod is called.
I was very surprised realizing that the @PostConstruct is not called during the bean's @PostConstruct method call, but between the construction of the bean and calling the bean's @PostConstruct method. Also the call of the bean's @PostConstruct method is not intercepted at all, not by the interceptor's @PostConstruct method nor bi its @AroundInvoke method.
Is there any mistake on my side / my programs side?
Is there any way to intercept the bean's @PostConstruct method (same goes for the @PreDestroy method)?
I need to prepare the context(s) and fill them with some content. In addition it would be also nice for other method deep down the call stack later to know that the call was triggered by the container through one of those two methods.