[cdi-dev] intercepted private @PostConstruct method behaviour?

Martin Kouba mkouba at redhat.com
Mon Jan 7 03:40:53 EST 2013


my interpretation is that in this case there are two lifecycle callback
interceptor methods. The first on the target class (MyService). The
other one on the interceptor class (TransactionalInterceptor). Each time
a new contextual instance of MyService is initialized all the lifecycle
callback interceptor methods are invoked according to the rules defined
in the Interceptors spec (Multiple Callback Interceptor Methods for a
Life Cycle Callback Event) -> TransactionalInterceptor first.

With regards the manual invocation of doTheInit (via a contextual
reference to the bean):
* according to the CDI spec (7.2 Container invocations and
interception), such an invocation will result in a regular business
method invocation (aroundInvoke intercepted, decorated, etc.)
* and again both lifecycle callbacks will only be invoked if a new
contextual instance of MyService is initialized

Re TCK - raise an issue please :-)


Dne 5.1.2013 15:24, Mark Struberg napsal(a):
> I guess I found the answer by studying the interceptors spec. It states that
> "The PostConstruct and PreDestroy, annotations are used to define an interceptor
> method for a lifecycle callback event."
> I assume that those are really only meant for 'lifecycle callback events' and must _not_ get invoked if they got called manually.
> Thus postConstructInterception will also get called for the private method but NOT for a manual invocation if the doTheInit would be public.
> Is this interpretation correct?
> Can we have a TCK for it? :D
> LieGrue,
> strub
> ----- Original Message -----
>> From: Mark Struberg <struberg at yahoo.de>
>> To: cdi-dev <cdi-dev at lists.jboss.org>
>> Cc: 
>> Sent: Saturday, January 5, 2013 2:56 PM
>> Subject: [cdi-dev] intercepted private @PostConstruct method behaviour?
>> Hi folks!
>> What happens if I have a 
>> @Transactional
>> public class MyService {
>>  @PostConstruct
>>  private void doTheInit() {...}
>> Where the interceptor looks like
>> @Interceptor @Transactional 
>> public class TransactionalInterceptor {
>>  @PostConstruct
>>  public void postConstructInterception(InvocationContext ic) {..}
>> Question a.) does the @Transactional interceptor still apply to the _private_ 
>> doTheInit() method?
>> Question b.) consider the doTheInit() method being changed to public and it will 
>> get invoked by a user. Does the postConstructInterception still get invoked? Or 
>> must it only get invoked for _real_ PostConstruct actions triggered by the 
>> container?
>> LieGrue,
>> strub

More information about the cdi-dev mailing list