JBoss.org Community Documentation
By default, when the application is deployed in a jar, session beans will bind to JNDI in the form ejbName/remote
for remote
interfaces and ejbName/local
in the case of local interfaces. When the EJBs are deployed in an .ear file, the default
jndi binding will be prepended by the name of the .ear file. So if the ear file name is foo.ear
the default jndi
names would be foo/EJB-NAME/remote
and foo/EJB-NAME/local
. You can override this behavior
by defining your own @org.jboss.ejb3.annotation.LocalBinding
and/or @org.jboss.ejb3.annotation.RemoteBinding
.
To change the JNDI name for your local interface use the @org.jboss.ejb3.annotation.LocalBinding
annotation.
@Stateless @LocalBinding(jndiBinding="custom/MySession") public class MySessionBean implements MySession { }
To change the JNDI name for your remote interface use the @org.jboss.ejb3.annotation.RemoteBinding
annotation.
@Stateless @RemoteBinding(jndiBinding="custom/remote/MySession") public class MySessionBean implements MySession { }
Persistence units are not bound into JNDI by default. You can bind them by defining some jboss specific properties in persistence.xml.
<persistence> <persistence-unit name="manager1"> <jta-data-source>java:/DefaultDS</jta-data-source> <jar-file>MyApp.jar</jar-file> <class>org.acme.Employee</class> <class>org.acme.Person</class> <class>org.acme.Address</class> <properties> <property name="jboss.entity.manager.jndi.name" value="java:/Manager1"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/Manager1Factory"/> </properties> </persistence-unit> </persistence>
Open up org.jboss.tutorial.jndibinding.client.Client
.
You'll see that it looks up the stateless bean under "Calculator". 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 "jndibinding" 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