1 Reply Latest reply on Jan 5, 2005 10:42 AM by Mark Newton

    unable to lookup an EJB from a JavaBean

    Hussein Baghdadi Novice

      Hi all.
      I'm creating a J2EE application.
      my web application contains a simple JavaBean that hides the operation of locating my Session EJB.

      Object obj = ic.lookup("java:comp/env/ejb/Liga");
      LigaHome home = (LigaHome)PortableRemoteObject.narrow(obj, LigaHome.class);

      this JavaBean will be used by servlets, JSPs.
      this is the important part of jboss.xml :


      when trying to use the application, I got the exception :
      javax.naming.NameNotFoundException: ejb not bound
      I changed <jndi-element> to Liga , I got the same exception
      the application is only works if I do the following :
      Object obj = ic.lookup("Liga");
      any ideas ???

        • 1. Re: unable to lookup an EJB from a JavaBean
          Mark Newton Apprentice


          The javax.naming.NameNotFoundException is being thrown because you have bound the EJB into the global namespace with the name 'ejb/Liga' but you are looking for it in the ENC namespace (java:comp/env).

          When you changed the jndi-name to Liga and used the following code, you correctly lookup the bean using JNDI:

          Object obj = ic.lookup("Liga");

          However as you are no longer using the ENC namespace your web application isn't as portable as it could be. If the EJB is bound to a different name, like it was before 'ejb/Liga', then you will have to change the lookup string in your source code to 'ejb/Liga' and recompile it in order for it to work.

          Ideally what you should do is add an <ejb-ref> or <ejb-local-ref> element to your web.xml file and then add the corresponding <ejb-ref> or <ejb-local-ref> element to your jboss-web.xml file. These tags map your ENC name to the global name which the EJB is really bound to. You can then use:

          Object obj = ic.lookup("java:comp/env/ejb/Liga");

          hopefully this is enough information to get you on the right track.