struts 中的 JMS 队列连接工厂

问题描述 投票:0回答:1

我正在尝试将 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 作为消息代理。

tomcat jms struts
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.