0 Replies Latest reply on Jan 24, 2012 7:06 PM by Amit Yadav

    JBoss 5.1| NameNotFoundException when referencing EJB2 bean from @PostContruct applied method of EJB3

    Amit Yadav Newbie

      Our application uses ejb2.0 and ejb3.0. All ejb2 beans are packaged in app-ejb.jar and all ejb3 beans are packaged in app-ejb3.0.jar. These jar files (app-ejb.jar and app-ejb3.0.jar) are packaged in single EAR file i.e. application.ear. Our project currently uses JBoss 4.2.3 and now I am trying to migrate it to JBoss 5.1.

       

      While deploying application.ear, I am getting javax.naming.NameNotFoundException:

       

      14:47:23,046 ERROR [STDERR] javax.naming.NameNotFoundException: com.myrio.tm.docgen.UpdateRegistryHome not bound

      14:47:23,046 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

      14:47:23,062 ERROR [STDERR]     at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)

      14:47:23,062 ERROR [STDERR]     at org.jnp.server.NamingServer.getObject(NamingServer.java:785)

      14:47:23,062 ERROR [STDERR]     at org.jnp.server.NamingServer.lookup(NamingServer.java:443)

      14:47:23,062 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)

      14:47:23,062 ERROR [STDERR]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)

      14:47:23,062 ERROR [STDERR]     at javax.naming.InitialContext.lookup(InitialContext.java:351)

       

      A) I found below lines in logs (appear before NameNotFoundException):

       

      14:47:17,343 INFO  [EjbDeployer] installing bean: ejb/totalmanage-ejb.jar#com.myrio.tm.docgen.UpdateRegistryHome,uid27736269

      14:47:17,343 INFO  [EjbDeployer]   with dependencies:

      14:47:17,343 INFO  [EjbDeployer]   and supplies:

      14:47:17,343 INFO  [EjbDeployer] jndi:com.myrio.tm.docgen.UpdateRegistryHome

       

      B) And, below lines appear in logs after NameNotFoundException exception:

       

      14:47:34,015 INFO  [EjbModule] Deploying com.myrio.tm.docgen.UpdateRegistryHome

      // logging for other beans

      14:49:39,230 INFO  [BaseLocalProxyFactory] Bound EJB LocalHome 'com.myrio.tm.docgen.UpdateRegistryHome' to jndi 'com.myrio.tm.docgen.UpdateRegistryHome'

       

      C) EJB3 bean class is implemented like:

       

      @Stateless(name = "DocumentBuilderBean")

      public class DocumentBuilderBeanImpl implements DocumentBuilderBean {

       

      private UpdateRegistry updateRegistry;

       

           @PostConstruct

           private void init() {

                 try {         

                     InitialContext ic = new InitialContext();

                      UpdateRegistryHome home == (UpdateRegistryHome)ic.lookup("com.myrio.tm.docgen.UpdateRegistryHome");

                      updateRegistry = home.create();

                 }       

                 catch (CreateException ex) {

                      logger.error("Error initializing update registry reference (create) ");

                }

           }

           // other methods

      }

       

      [DocumentBuilderBean is local interface]

       

      D) UpdateRegistryHome & UpdateRegistry interfaces are like:

       

      => public interface UpdateRegistryHome extends EJBLocalHome {

                UpdateRegistry create() throws CreateException;    

           }

      => public interface UpdateRegistry extends EJBLocalObject {

                // few methods

           }

      => all required entries are there in ejb-jar.xml file

      -----------------------------------------------------------------------------------------------------------------------------------------

       

      The problem here is 'DocumentBuilderBean' is trying to lookup ejb2 bean (in @PostConstruct applied method 'init') which is still not bound to JNDI. If i remove ejb2 lookup from init method; everything works fine. No problem when running same ear on Jboss 4.2.3.

       

      Can some one suggest me how to make sure 'DocumentBuilderBean' instance is created (and @PostConstruct method is invoked) only after ejb2 is successfully deployed and bound to jndi)?

       

      Thanks