EJB Annotations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 37: Line 37:


=@javax.annotation.Resource=
=@javax.annotation.Resource=
=@javax.ejb.Remote=
=@javax.ejb.Local=

Revision as of 23:33, 24 March 2017

Internal

Overview

If an XML deployment descriptor containing the same semantics exists, the XML content overrides the annotation.

@javax.ejb.EJB

Used to request the container to inject a reference to an EJB.

@EJB
private MyBusinessInterface myEjb;

The @EJB annotation is processed as follows:

  • The JAR of the referencing bean is searched for an EJB with the interface used in the @EJB injection. If there are more than one EJB that publishes the same business interface, an exception is thrown, otherwise the matching bean is returned.
  • The EAR of the deployment is searched. If there are duplicates, an exception is thrown, otherwise the matching bean is returned.
  • Search globally in the JBoss instance runtime for an EJB of that interface. If there are duplicates, an exception is thrown, otherwise the matching bean is returned.

beanName

The value optionally specified here corresponds to <ejb-link>. If beanName is defined, the algorithm described above is used, except that beanName is used as key in the search. The "#" syntax allows to put a relative path to a jar in the EAR where the EJB you are referencing is located. More details in the EJB 3.1 specification.

mappedName

The annotation has a "mappedName()" attribute. The specification designates it as vendor specific metadata. JBoss uses this metadata to specify the global JNDI name of the EJB. If mappedName() is specified, all other attributes (name, description, beanName, beanInterface, lookup) are ignored and this global JNDI name is used for binding.

@EJB(mappedName = "/somehting/something")
private MyBusinessInterface myEjb;

For a working example, see Session EJB and Servlet in Different Deployment Units on Same JBoss Instance.

@javax.annotation.Resource

@javax.ejb.Remote

@javax.ejb.Local