JBoss.org Community Documentation
Take a look at the META-INF/ejb-jar.xml
and org.jboss.tutorial.stateful_deployment_descriptor.bean.ShoppingCartBean
.
You specify a stateful bean with the "session" and "session-type" tags. Note that all bean types in EJB 3.0 are homeless,
so there is no requirement for a "home" or "local-home" tag. The bean class is specified with the "ejb-class" tag.
ShoppingCartBean also implements a business-remote interface. Take a look at org.jboss.tutorial.stateful_deployment_descriptor.bean.ShoppingCart
.
To define this as the business-remote interface of ShoppingCartBean you need to use the "business-remote" tag in the ejb-jar.xml. Here's the META-INF/ejb-jar.xml
:
<session> <ejb-name>ShoppingCart</ejb-name> <business-remote>org.jboss.tutorial.stateful_deployment_descriptor.bean.ShoppingCart</business-remote> <ejb-class>org.jboss.tutorial.stateful_deployment_descriptor.bean.ShoppingCartBean</ejb-class> <session-type>Stateful</session-type> <remove-method> <bean-method> <method-name>checkout</method-name> </bean-method> <retain-if-exception>false</retain-if-exception> </remove-method> <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.
Take another look at META-INF/ejb-jar.xml
. Look for the "remove-method" tag.
Instead of explicitly calling EJBObject.remove() in your applications and thus polluting it further with J2EE specific code,
any method specified in the "remove-method" tag will cause the stateful bean instance to be removed from the container
at the end of the method call. This deployment descriptor behavior mimics the @Remove
annotation.
The CalculatorBean will have its remote interface bound in JNDI. Take a look at META-INF/jboss.xml
.
Note the jndi-name
tag. This specifies the jndi binding for the remote interface of the bean.
Open up org.jboss.tutorial.stateful_deployment_descriptor.client.Client
.
You'll see that it looks up the stateful bean under its jndi name. Also notice that there is no Home interface
and you can begin executing on the stateful bean right away. When you access the bean in JNDI, an instance of the stateful
bean will be created on the server. So, when you need a different instance of the stateful bean, you do an additional
jndi lookup to get this new reference.
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 "stateful_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] Buying 1 memory stick [java] Buying another memory stick [java] Buying a laptop [java] Print cart: [java] 2 Memory stick [java] 1 Laptop [java] Checkout [java] Should throw an object not found exception by invoking on cart after @Remove method [java] Successfully caught no such object exception.
$ mvn clean install -PRunSingleTutorial