JBoss.org Community Documentation
It is very easy to create a Stateless Bean with EJB 3.0. All bean types are homeless in EJB 3.0 so all you have to do to
create a Stateless bean is to create a bean class and have it implement at least one interface. Take a look at
org.jboss.tutorial.stateless.bean.CalculatorBean
The first thing to notice is that the class is tagged as @Stateless
. 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 remote interface of the EJB the other is the local interface.
Take a look at org.jboss.tutorial.stateless.bean.CalculatorRemote
.
To define this as the remote interface of Calculator bean
you either annotate the bean class and specify what the remote interfaces are, or you annotate each remote interface the bean class
implements with @javax.ejb.Remote. only need to annotate the bean class with @javax.ejb.Remote
.
Similar for org.jboss.tutorial.stateless.bean.CalculatorLocal
as you need to annotate the bean
class with @javax.ejb.Local
for it to be the local interface of the CalculatorBean.
The Calculator bean will have two JNDI bindings for the remote and Local interface. By default, JBoss will use ejbName/local and ejbName/remote for the local and remote interfaces, respectively.
Open up org.jboss.tutorial.stateless.client.Client
.
You'll see that it looks up the stateless bean under "ejbName/remote". 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" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant $ ant run
$ mvn clean install -PRunSingleTutorial