JBoss.org Community Documentation
CalculatorBean is defined as a stateless session bean through the <session>
and
<session-type>
elements. This marks the class as a stateless bean and the deployer will
deploy that class as a stateless bean EJB container.
CalculatorBean also implements two interfaces. One is the business-remote interface of the EJB the other is the business-local
interface. Take a look at org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorRemote
. To define this
as the business-remote interface of Calculator bean you specify the interface with the <remote>
tag.
Similarly for org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorLocal
you need to specify the
business-local interface with the <local>
tag. Here's the META-INF/ejb-jar.xml
:
<session> <ejb-name>Calculator</ejb-name> <business-local>org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorLocal</business-local> <business-remote>org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorRemote</business-remote> <ejb-class>org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session>
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.
The Calculator bean will have two JNDI bindings for the remote and Local interface. The META-INF/jboss.xml
through the <jndi-name>
and the <local-jndi-name>
specifies the jndi-name
for the remote and the local interfaces, respectively:
<session> <ejb-name>Calculator</ejb-name> <jndi-name>org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorRemote</jndi-name> <local-jndi-name>org.jboss.tutorial.stateless_deployment_descriptor.bean.CalculatorLocal</local-jndi-name> </session>
Open up org.jboss.tutorial.stateless_deployment_descriptor.client.Client
.
The client looks up the bean using the jndi-name specified in the jboss.xml. Also notice that there is no Home interface
and you can begin executing on the stateless bean right away.
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 "stateless_deployment_descriptor" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant $ ant run run: [java] 1 + 1 = 2 [java] 1 - 1 = 0
$ mvn clean install -PRunSingleTutorial