11 Replies Latest reply on Dec 1, 2010 1:12 AM by jaikiran

    JNDI EJB lookup in jboss5.1.0 GA

    varsha7

      I am running into issues where I have to change the way we do ejb lookups by specifying the ear file name prefix along with the ejb name.

       

      Is there a way in jboss 5 to bind the ejb differently so that the ear file name prefix is ignored? I want to make the code as much flexible as possible so that it is not dependent on the ear file name to lookup ejbs.

       

      Eg:

      Bean b = (Bean)ctx.lookup("myear/MyBean/local");

       

      myear = ear file name

      MyBean= ejb

       

      I am looking for a way to not hardcode the “myear”.

       

      Any help is appreciated.

       

      Thanks

        • 1. Re: JNDI EJB lookup in jboss5.1.0 GA
          wdfink

          What about the dependency injection? You using local interface that make me feel you are inside the container or inside your ear, right?

          Do you try

          @EJB BeanLocal myBean;

          This will inject the local interface before your code is called.

          • 2. Re: JNDI EJB lookup in jboss5.1.0 GA
            jaikiran
            • 3. Re: JNDI EJB lookup in jboss5.1.0 GA
              varsha7

              Thank you. I read that chapter and tried it out but am having problems. My ejb is deployed in an ear file.

               

              Here is my code:

               

              import org.jboss.ejb3.annotation.LocalBinding;
              import org.jboss.ejb3.annotation.RemoteBinding;

               

              @Stateless
              @LocalBinding(jndiBinding="ABCBean/local")
              @RemoteBinding(jndiBinding="ABCBean/remote")

              public class ABCBean implements ABCLocal, ABCRemote {

              .... }


              I lookup for that ejb from a servlet in a different package.

              try

              {
              return (ABCRemote)ctx.lookup("ABCBean/remote");
              }
              catch (NameNotFoundException e) { ..
              }

              I get a javax.naming.NameNotFoundException: ABCBean/remote could not be found during jboss startup. I am on jboss 5.1.0GA.


              Thanks

               

              • 4. Re: JNDI EJB lookup in jboss5.1.0 GA
                jaikiran

                When are you doing that lookup in the servlet? In its init() method? Is that a load-on-startup servlet? Make sure that the beans are first deployed and then the lookup is done. You can also check the "JNDIView" MBean to list the jndi names of the beans you deployed.

                • 5. Re: JNDI EJB lookup in jboss5.1.0 GA
                  varsha7

                  The lookup is done in the servlet's init() method. I checked the  JNDIView and see the bean deployed there. How do I know if the bean is deployed first before the lookup is done? Is the JNDI view listed in the order of deployment?

                  • 6. Re: JNDI EJB lookup in jboss5.1.0 GA
                    jaikiran

                    Varsha Hardikar wrote:

                     

                    The lookup is done in the servlet's init() method.

                    I guess then it's being triggered before the bean is bound to JNDI.

                     

                    Varsha Hardikar wrote:

                     

                    How do I know if the bean is deployed first before the lookup is done?

                    The logs that you see on the console will show you the jndi bindings too. So ideally, you should see the beans being bound first before the servlet init() tries to lookup. Can you post the entire logs that you see on the console (not the server.log)

                    • 7. Re: JNDI EJB lookup in jboss5.1.0 GA
                      varsha7

                      This is what I see in the log:-

                       

                      16:40:43,605 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                      ABCBean/remote - EJB3.x Default Remote Business Interface
                      myear/ABCBean/remote-com.mycompanyabc.interfaces.SecurityManagerRemote - EJB3.x Remote Business Interface
                      ABCBean/local - EJB3.x Default Local Business Interface
                      myear/ABCBean/local-com.mycompany.abc.interfaces.SecurityManagerLocal - EJB3.x Local Business Interface

                       

                      6:41:14,561 ERROR [[/myui]] Servlet /myui threw load() exception
                      javax.naming.NameNotFoundException: ABCBean/remote could not be found
                      at com.mycompany.abc.gui.servlet.MyServlet.getMyManager(MyServlet.java:120)
                      at com.mycompany.abc.gui.servlet.MyServlet.init(MyServlet.java:46)

                       

                      Looks like the bean is bound first before the servlet init() tries to lookup but I am not sure what the two lines mean and which jndi binding is picked up.

                       

                      ABCBean/remote - EJB3.x Default Remote Business Interface
                      myear/ABCBean/remote-com.mycompany.abc.interfaces.MyRemote - EJB3.x Remote Business Interface

                      • 8. Re: JNDI EJB lookup in jboss5.1.0 GA
                        jaikiran

                        Please post the lookup code from your servlet.

                         

                        [Edit: You did post the servlet code a few posts back. The code looks OK. How do you get the "ctx" object? Other than that it looks fine]

                        • 9. Re: JNDI EJB lookup in jboss5.1.0 GA
                          varsha7

                          There was something wrong with my setup. Jaikiran, the solution you suggested works. Thank you very much for your help.

                          • 10. Re: JNDI EJB lookup in jboss5.1.0 GA
                            varsha7

                            I am wondering if

                            import org.jboss.ejb3.annotation.LocalBinding;
                            import org.jboss.ejb3.annotation.RemoteBinding are backwards compatible for jboss 4.2.3-GA.. I tried the same code which was working on jboss 5 on jboss 4.2.3.GA and get a NameNotFoundException when doing the lookup on the ejb.

                            • 11. Re: JNDI EJB lookup in jboss5.1.0 GA
                              jaikiran

                              User User11 wrote:

                               

                              I am wondering if

                              import org.jboss.ejb3.annotation.LocalBinding;
                              import org.jboss.ejb3.annotation.RemoteBinding are backwards compatible for jboss 4.2.3-GA..

                              No they are not. The annotation package changed from AS4 to AS5. For AS4, the annotations reside in a different package. See this for AS4 http://docs.jboss.org/ejb3/docs/tutorial/jndibinding/jndi.html