JBoss.org Community Documentation
Resources (e.g. data sources, JavaMail sessions, JMS queues) may be added to the local jndi namespace (ENC) of individual EJBs. This is to separate the jndi names used in the bean code from the global jndi bindings set by the bean deployer. The mapping of the bean local jndi binding and the global binding may be handled via the ejb-jar.xml and jboss.xml deployment descriptors.
Take a look at META-INF/ejb-jar.xml
. For ENCBean
, there are 3
<resource-ref>
elements indicating resource reference names and types.
Take a look at META-INF/jboss.xml
. For ENCBean
, there are again
3 <resource-ref>
elements indicating resource reference names and either the global jndi
binding via the <jndi-name>
element or the resource name. Resource managers
are used to map resource names to global jndi bindings via the <resource-managers>
element.
Take a look at org.jboss.tutorial.resource_ref.bean.TestENCBean
. Each one of the resources are accessed from the
bean local jndi namespace (i.e. java:comp/env) by the value set in the <res-ref-name>
values
in the deployment descriptors.
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 "resource_ref" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant $ ant run run: [java] Successfully accessed bean resource references
$ mvn clean install -PRunSingleTutorial
On the server you will notice these logs:
13:44:09,500 INFO [TestENCBean] Found data source resource ref 13:44:09,500 INFO [TestENCBean] Found mail resource ref 13:44:09,500 INFO [TestENCBean] Found jms queue resource ref 13:44:09,500 INFO [TestENCBean] Found jms queue resource env ref