5 Replies Latest reply: Sep 13, 2012 6:39 AM by 940787 RSS

    Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)

    940787
      Hello, for days we look for a response to this question:

      We have a local EJB 3.0 defined as usual with annotations. We know EJB 3.0 doesn't define a standard jndi name to lookup in the InitialContext, so, what is the name in Weblogic 10.3?

      E.g. if we have a EJB module with the following classes (package "test"):

      @Stateless
      public class Hello implements HelloLocal {  ... }

      @Local
      public interface HelloLocal { ... }

      and a standard (pojo) class (not a EJB):

      public class Foo {
      InitialContext ctx = null;
      try {
      ctx = new InitialContext();
      Object o = ctx.lookup("XXXXXX");

      } ....
      }

      We try a lot of names for XXXXXX unsuccessfully. If we iterate over the JNDI context we found that exists a binding in "java:module" with then name "test.HelloLocal" but when do a lookup:

      ctx.lookup("java:module/test.HelloLocal")

      an exception is thrown. We know that "java:module" is part of the EJB 3.1 specification but we try a lot of things ...


      Thanks in advance.
        • 1. Re: Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)
          René van Wijk
          Note that WebLogic does not make local interfaces available on the global JNDI tree (not specified in the EJB3.0 specification so some vendors do others do not)

          To access the local interface you need to define local references for your component, for example, in web.xml
          <ejb-local-ref>     
              <ejb-ref-name>ejb/HelloLocal</ejb-ref-name>     
              <local>package.name.HelloLocal</local>     
          </ejb-local-ref>
          To lookup a reference to the bean you can use - java:comp/env/ejb/HelloLocal:
          InitialContext context = null;
          try {
                  context = new InitialContext();
                  HelloLocal hello = (HelloLocal) context.lookup("java:comp/env/ejb/HelloLocal");
                  hello.doSomethingIfItWherePresentInTheEJB();
          } catch (NamingException e) {
          }
          • 2. Re: Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)
            940787
            Thanks René, I understand but the problem is when no web module exists, so we can't add an entry in web.xml descriptor.

            The class that make the lookup is inside the same EJB Module containing the local EJB. We try adding an entry in weblogic-ejb-jar.xml descriptor but because we use annotations this descriptor seems to be ignored.

            thanks.
            • 3. Re: Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)
              René van Wijk
              You can also put an ejb-local-ref in the ejb-jar.xml.

              "The ejb-ref and ejb-local-ref elements in the ejb-jar.xml descriptor are used to map references
              to other EJBs into the local java:comp/env environment. The application code then uses logical JNDI
              names in the java:comp/env namespace, and the deployment descriptor specifies how the container
              should resolve these names."

              Some examples are given here: http://sqltech.cl/doc/oas10gR31/web.1013/b28221/usclient003.htm
              • 4. Re: Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)
                940787
                The EJB annotation @Stateless is compatible to have the bean in the ejb-jar.xml? If yes, what should be the value of <local-home>?

                "<local-home>" is mandatory and if using annotations no home is needed and not declared anywhere.

                <enterprise-beans>
                <session>
                <ejb-name>Hello</ejb-name>
                <local>test.HelloLocal</local>

                <local-home>xxxx</local-home>

                <ejb-class>test.Hello</ejb-class>
                <ejb-local-ref>
                <ejb-ref-name>ejb/Hello</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local>Hello</local>
                </ejb-local-ref>
                </session>
                </enterprise-beans>
                • 5. Re: Unable to lookup in InitialContext a Local EJB in Weblogic 10.3.5 (EJB 3.0)
                  940787
                  Hello again, finally I found how to define the ejb-jar.xml. If another have the same problem I paste an example:

                  <enterprise-beans>
                  <session>
                  <ejb-name>Hello</ejb-name>
                  <ejb-class>test.Hello</ejb-class>
                  <ejb-local-ref>
                  <ejb-ref-name>ejb/Hello</ejb-ref-name>
                  <ejb-ref-type>Session</ejb-ref-type>
                  <local>test.HelloLocal</local>
                  <ejb-link>test2-ejb.jar#Hello</ejb-link>
                  </ejb-local-ref>
                  </session>
                  </enterprise-beans>


                  And as René says you can obtain the reference in the local enc:


                  HelloLocal hello = (HelloLocal)ctx.lookup("java:comp/env/ejb/Hello");


                  regards.