首页 > 解决方案 > 尝试使用 JNDI 获取 OpenMQ 连接工厂时出现 NameNotFoundException

问题描述

我正在尝试通过 JNDI 将 OpenMQ 5.0 与 Tomcat 一起使用。以下是我在 Tomcat 中所做的配置。

server.xml

<Resource name="jms/sampleFactory" 
          auth="Container"   
          type="com.sun.messaging.QueueConnectionFactory" 
          description="OpenMQ Queue Connection Factory"
          factory="com.sun.messaging.naming.QCFObjectFactory" 
          securityPort="7676"
          parm="--"
          subnet="0"
          host="-s localhost"
          ackTimeout="-t 30000"
          version="1.1" />
<Resource name="jms/sampleQueue" 
          auth="Container" 
          type="com.sun.messaging.Queue" 
          description="OpenMQ Queue"
          factory="com.sun.messaging.naming.QObjectFactory" 
          destName="sampleQueue"
          version="1.1" />

context.xml

<Context>    
    <ResourceLink global="jms/sampleFactory" name="jms/sampleFactory" 
        type="javax.jms.ConnectionFactory"/>
    <ResourceLink global="jms/sampleQueue" name="jms/sampleQueue" 
        type="javax.jms.Queue"/>
</Context>

网络应用web.xml

<resource-ref>
    <res-ref-name>jms/sampleFactory</res-ref-name>
    <res-type>javax.jms.ConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref> 
<resource-ref>
    <res-ref-name>jms/sampleQueue</res-ref-name>
    <res-type>javax.jms.Queue</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

现在,当我尝试这样做时,initialContext.lookup("java:/comp/env/jms/sampleFactory")它会抛出NameNotFoundException

代理已启动并正在运行。

谁能指导我可能是什么问题?

标签: tomcatweb-applicationsjmsintegrationjndi

解决方案


推荐阅读