JBoss.org Community Documentation
EJB 3.0 is backward compatible to EJB 2.x clients and supports the use of local and remote home interfaces as well as initialization methods (e.g. ejbCreate()). This capability is configured through annotations and/or through deployment descriptors.
Take a look at org.jboss.tutorial.ejb21_client_adaptors.bean.Session1Bean
. Note
that the class is annotated with @RemoteHome
and the ejbCreate()
method is annotated
with @Init
. The former annotation indicates that the bean provides a EJB 2.1 style home interface. The latter
annotation indicates that when the create()
method is invoked from the home interface, the bean is initialized
via the ejbCreate
method.
The initialization method (annotated with @Init
) name is not restricted to be ejbCreate(). You can
specify any other name for that method.
org.jboss.tutorial.ejb21_client_adaptors.bean.Session2Bean
illustrates the use of a local home interface.
There's a very important difference between the remote
and a business-remote
interface. The EJB2.x remote interfaces, which extend from EJBObject, are referred through the <remote>
tag in the ejb-jar.xml. On the other hand, the EJB3 style Plain Old Java Interface which is implemented by your EJB3 style
POJO bean is known as the business-remote interface and is represented by the @Remote
and it's
corresponding <business-remote>
tag in ejb-jar.xml.
Similar is the case with <local>
and the <business-local>
tags in ejb-jar.xml.
In this tutorial, you will notice that we are using remote
and local
interfaces and
not business-remote
and business-local
interfaces.
Since we are not using any business-remote
or business-local
interfaces, in this tutorial,
unlike the "jndibinding" tutorial, we cannot use the @RemoteBinding
or @LocalBinding
annotations to bind the EJBs. Instead, we configure the jndi-names for these beans through the META-INF/jboss.xml
:
<session> <ejb-name>Session1</ejb-name> <jndi-name>Session1Remote</jndi-name> </session> <session> <ejb-name>Session2</ejb-name> <local-jndi-name>Session2Local</local-jndi-name> </session>
Similarly, org.jboss.tutorial.ejb21_client_adaptors.bean.DeploymentDescriptorSession1Bean
and
org.jboss.tutorial.ejb21_client_adaptors.DeploymentDescriptorSession2Bean
mimic the behavior of
the first two beans, but use deployment descriptors to indicate the home interface(s) and initialization method(s).
Take a look at the META-INF/ejb-jar.xml
. Note the home
and local-home
tags that indicate the respective home interfaces. Also, note the init-method
tag that indicates the
initialization method(s) executed when beans are created via the home interface(s).
To build and run the example, make sure you have installed JBoss 5.x. See the Section 1.1, “JBoss Application Server 5.x” for details.
From the command prompt, move to the "ejb21_client_adaptors" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant $ ant run run: [java] Session1 init value is initialized [java] Session2 init value is initialized [java] DeploymentDescriptor Session1 init value is initialized [java] DeploymentDescriptor Session2 init value is initialized
$ mvn clean install -PRunSingleTutorial