1 Reply Latest reply on Apr 6, 2007 1:33 PM by William DeCoste

    @EJB annotation doesn't lookup globally JBoss

    Dirk Estievenart Newbie

      Hi,


      I have 2 ear's, say earA and earB. I have a session bean (say SessionA) that needs to call a method on a session bean (say SessionB) in earB.

      I implemented this like this:

      @Stateless
      public class SessionBeanA implements SessionBeanALocal {
       @EJB(mappedName="earB/SessionBeanB/local")
       SessionBeanB beanB;
       ...
      


      which is exactly how it appears in the JNDI view.
      However, during execution, the beanB variable is always null.

      I have tried all possible formats for the mapped name, it never works:
      "SessionBeanB/local"
      "earB/SessionBeanB"
      "SessionBeanB"
      ...

      It works fine if beanB is in the same ear as beanA. It also works fine if I do a classical lookup :
      InitialContext initCtx = new InitialContext();
      SessionBeanB beanB= (SessionBeanB)initCtx.lookup("earB/SessionBeanB/local");
      


      If I understand the EJB3 docs well, it should be no issue that the beanB is in another ear, or is it?


      Rules for the @EJB annotation

      * The @EJB annotation also has a mappedName() attribute. The specification leaves this a vendor specific metadata, but JBoss recognizes mappedName() as the global JNDI name of the EJB you are referencing. If you have specified a mappedName(), then all other attributes are ignored and this global JNDI name is used for binding.
      * If you specify @EJB with no attributes defined:

      @EJB ProcessPayment myEjbref;

      Then the following rules apply:
      o The EJB jar of the referencing bean is contained in is search for another EJB with the same interface. If there are more than one EJB that publishes same business interface, throw an exception, if there is one, use that one.
      o Search the EAR for EJBs that publish that interface. If there are duplicates, throw an exception, otherwise return that one.
      o Search globally in JBoss for an EJB of that interface. Again, if duplicates, throw an exception
      * @EJB.beanName() corresponds to <ejb-link>. If the beanName() is defined, then use the same algorithm as @EJB with no attributes defined except use the beanName() as a key in the search. An exception to this rule is if you use the ejb-link '#' syntax. The '#' syntax allows you to put a relative path to a jar in the EAR where the EJB you are referencing lives. See spec for more details




        • 1. Re: @EJB annotation doesn't lookup globally JBoss
          William DeCoste Apprentice

          What is the local interface for SessionBeanB? I'm guessing you are injecting into a field of the bean tye not the interface type (i.e. SessionBeanBLocal not SessionBeanB). Are you seeing anything in the logs at deployment time?

          The default JNDI bindings for an EJB3 are ejbName/remote and ejbName/local for the remote and local business interfaces. If the EJB3 is deployed in an .ear, the default jndi bindings are earName/ejbName/remote and earName/ejbName/local. You can override the default with the @RemoteBinding and @LocalBinding annotations or the <jndi-name> and <local-jndi-name> in jboss.xml