我正在尝试将JMS邮件发件人集成到基于struts的Web应用程序中。我在方法中定义了消息发送方,并在actionForm的execute方法中调用了方法。我得到的错误是
javax.naming.NameNotFoundException: Name queueConnectionFactory is not bound in this Context
我猜错误就在这个地方
try {
connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");
destination = (Destination)jndiContext.lookup(destinationName);
} catch (NamingException e) {
e.printStackTrace();
System.exit(1);
}
我正在使用ActiveMQ作为消息代理。
答案 0 :(得分:2)
在Web层中,您必须使用conn的完整JNDI名称。工厂,即java:comp/env/queueConnectionFactory
。
在Tomcat中,您还需要在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>