Chapter 2. References and Injection XML and Annotations

2.1. Intro

This section covers how JBoss implements @EJB and @Resource. Please note that XML always overrides annotations.

2.2. EJB references

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:
    • 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.
    • Search the EAR for EJBs that publish that interface. If there are duplicates, throw an exception, otherwise return that one.
    • 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

For XML the same rules apply as annotations exception <mapped-name> is the ejb-jar.xml equivalent to @EJB.mappedName().