[jboss-user] [EJB 3.0] - @EJB annotation doesn't lookup globally JBoss

estiedi do-not-reply at jboss.com
Thu Apr 5 05:47:02 EDT 2007


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:

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?

anonymous wrote : 
  |  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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034937#4034937

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034937

More information about the jboss-user mailing list