JBoss.org Community Documentation

Chapter 25. Introduction to binding the resources to ENC of EJB3 beans

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.

ejb-jar.xml :

Take a look at META-INF/ejb-jar.xml. For ENCBean, there are 3 <resource-ref> elements indicating resource reference names and types.

jboss.xml :

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.

TestENCBean.java :

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.

Building and Running

From the command prompt, move to the "resource_ref" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”

Ant Users:

Make sure your JBossAS-5.x is running

$ ant
$ ant run

     [java] Successfully accessed bean resource references


Maven Users: Make sure the AS is not running.

$ 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