At the moment I'm working on an application that has to use a connection factory. When I lookup the connection factory directly on a global level by the name set in WAS everything is working fine, but for means of decoupling I want to define a resource reference in my application and lookup that name. So I created following entry in my application.xml:
<resource-ref>
<res-ref-name>jms/connectionFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
What I do then inside my EJB is making following lookup:
ConnectionFactory connectionFactory =
(ConnectionFactory) ic.lookup("java:comp/env/jms/connectionFactory");
This leads to this exception:
javax.naming.NameNotFoundException: Name comp/env/jms not found in context "java:".
I also tried it with:
ConnectionFactory connectionFactory =
(ConnectionFactory) ic.lookup("java:app/jms/connectionFactory");
leading to:
javax.naming.NameNotFoundException: Context: BPMDev/applications/com.ibm.ws.AppNameSpaces/MAN_POT/root,
name: jms/connectionFactory: First component in name jms/connectionFactory not found.
Does anyone know what I'm doing wrong here? Thanks in advance!
Further investigations brought me to: Lookup jndi resources WebSphere 8.5, Spring 3.1.3, Hibernate 4.1.10 EJB 3
There the answer is contained:
Both the entry in the application.xml and the lookup have to be preceeded with java:app/env. For my case this is:
<resource-ref>
<res-ref-name>java:app/env/jms/connectionFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
and:
ConnectionFactory connectionFactory =
(ConnectionFactory) ic.lookup("java:app/env/jms/connectionFactory");