0
votes

I have integrated JMS in my project and getting the Exception as ActiveMQConnectionFactory cannot be cast to javax.jms.QueueConnectionFactory while calling the JMS receiver from servletcontext listener but it works fine from public static void main method and able to receive message from queue asynchronously.I am able to send the message to queue using queueconnection and queuesession from my web app and using the same qconnection approach in JMS receiver function which implements MessageListener interface.

Can any one suggest me what is the best way to start the JMS receiver or consumer automatically when web app starts because i use servletcontextlistener to start listening the message queue automatically.

(both JMS queuesender and queuereceiver works fine from public static void main method and problem starts only after calling the queuereceiver from contextinitialize method)

2

2 Answers

1
votes

Maybe this post can help you.

The cause there were two version of the ActiveMQ-jars in the classpath, said the poster.

In my case, the cause was 2 versions of javax.jms in the classpath: the one that came with ActiveMQ, and the one I was using to compile my sources (ActiveMQ is supposed to be just a test dependency for my application). I changed the scope of my maven dependency javax.jms:jms:1.1 from compile to provided, which removed the javax.jms-jar from my WAR file, and the exception disappeared.

0
votes

Yes there's a version problem, I was able to fix this problem by using these version of activemq, jms and j2ee dependencies.

ActiveMQ 5.8.0 and above

  • activemq-broker-5.8.0
  • activemq-client-5.8.0
  • geronimo-jms_1.1_spec-1.1.1
  • geronimo-j2ee-management_1.1_spec-1.0.1

Earlier version of ActiveMQ

  • activemq-core-5.5.1
  • geronimo-j2ee-management_1.0_spec-1.0
  • geronimo-jms_1.1_spec-1.1.1

Check the versions it'll help