[webbeans-dev] EJB lifecycle

Pete Muir pmuir at redhat.com
Thu Dec 18 18:33:35 EST 2008


Section 6.9 says that we should intercept the @PostConstruct of an EJB  
to do injection, initialization, interceptor stack binding etc. And  
this works well :-)

So, what I've done is:

    @PostConstruct
    public void postConstruct(InvocationContext invocationContext)
    {
       Class<?> beanClass = invocationContext.getTarget().getClass();
       Bean<?> bean =  
CurrentManager.rootManager().getBeanMap().get(beanClass);
       if (bean instanceof EnterpriseBean)
       {
          EnterpriseBean<Object> enterpriseBean =  
(EnterpriseBean<Object>) bean;
          enterpriseBean.postConstruct(invocationContext.getTarget());
       }

To get the relevant Bean, and then run the post construct tasks. I can  
see two flaws here. First, accessing the manager through current  
manager, second that there could be multiple Enterprise Beans  
registered for a particular bean class. In Seam there is some  
ThreadLocal used to hold the currently invoking bean. Does this seem  
like the best approach, or am I missing the obvious?



More information about the weld-dev mailing list