JMS queue connection factory in struts
I'm trying to integrate JMS message sender in a struts based web application. I have defined the message sender in a method and called the method in actionFor开发者_开发知识库m's execute method. The error i get is
javax.naming.NameNotFoundException: Name queueConnectionFactory is not bound in this Context
I guess the error is at this place
try {
connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");
destination = (Destination)jndiContext.lookup(destinationName);
} catch (NamingException e) {
e.printStackTrace();
System.exit(1);
}
I'am using ActiveMQ as the Message broker.
In the web layer you have to use full JNDI name of the conn. factory, i.e. java:comp/env/queueConnectionFactory
.
In Tomcat, you also need to declare it in the web.xml
:
<resource-ref id="ResourceRef_0">
<description>Logical mapping of QueueConnectionFactory</description>
<res-ref-name>queueConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
精彩评论