I have simple J2EE application which consists of following parts:
In post construct method I lookup EntityManager via JNDI and call some methods on it. The problem is that sometimes during application deployment I get :
javax.ejb.EJBException: java.lang.RuntimeException: javax.naming.NameNotFoundException: Main-PU not bound
As far as I understand it's expected behavior because JBoss doesn't have a way to know that post construct method should be called after persistence unit is bound to JNDI. In normal case I should use:
@PersistenceContext(name = "Main-PU") private EntityManager em;
in order to obtain persistence unit. But due to some historical reasons I use JNDI lookup. So my question is: are there any other ways to hint JBoss that post construct method should be called after persistence unit is completely deployed and bound to JNDI.
Afaik, there is some @Depends annotation which you can use for EJBs.
And this will make sure that dependency is resolved before you actually use the EJB.