jboss.xml Resource References
Resources (e.g. data sources, JavaMail sessions, JMS queues) may be added to the local jndi namespace of individual EJBs. This is to separate the jndi names used in the
bean code from the global jndi bindings set by the 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 ejb-jar.xml. For ENCBean, there are 3 <resource-ref> elements indicating resource reference names and types.
jboss.xml
Take a look at 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 TestENCBean.java. Each one of the resources are accessed from the bean local jndi
namespace (i.e. java:comp.ejb3/env) by the value set in the <res-ref-name> values in the deployment descriptors.
Building and Running
To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
Unix: $ export JBOSS_HOME=<where your jboss 4.0 distribution is>
Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is>
$ ant
$ ant run
run:
[java] Successfully accessed bean resource references
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