javax.naming.NamingException:无法创建ActiveMQConnectionFactory的资源实例

时间:2012-11-08 18:11:44

标签: java java-ee jms jndi

我知道这个问题已被多次询问,但即使在完成所有答案之后我仍然有例外。我的配置是:

context.xml中

<Context>
     <Resource
      name="jms/ProdConnectionFactory"
      description="Prod JMS Connection Factory"
      auth="Container"
      userName="" 
      password=""
      type="org.apache.activemq.ActiveMQConnectionFactory"
      factory="org.apache.activemq.jndi.JNDIReferenceFactory"
      brokerURL="tcp://jmshost:61616"
      brokerName="ProdActiveMQBroker"
   />
</Context>

的web.xml

<web-app>
    <resource-ref>
        <description>Prod Connection Factory</description>
        <res-ref-name>jms/ProdConnectionFactory</res-ref-name>
        <res-type>org.apache.activemq.ActiveMQConnectionFactory</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

Java代码:

Context context = new InitialContext();
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) context.lookup("java:comp/env/jms/ProdConnectionFactory");

我收到的例外是:

javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)

任何人都可以看看,让我知道我错在哪里。感谢

1 个答案:

答案 0 :(得分:0)

原因描述为here:appname.xml与context.xml不同,即它包含的context.xml中定义的资源较少。每次重新部署应用程序时都应更新appname.xml,但重新部署时会出现问题,这会导致appname.xml保持不变。更新appname.xml

后,问题已得到解决