Search code examples
javajakarta-eejmsjndi

javax.naming.NamingException: Cannot create resource instance of ActiveMQConnectionFactory


I know that this question has been asked many times, but I still have an exception even after following all the answers. My configs are:

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 code:

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

And the exception that I receive is:

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)

Can anyone take a look and let me know where I'm wrong. Thanks

L


Solution

  • The reason is described here: appname.xml is different than context.xml, i.e. it contains less resources defined in context.xml. appname.xml should be updated everytime a application is redeployed, but there's an issues in redeployment which leaves appname.xml unchanged. The issue is fixed after I update appname.xml

    L