Reputation: 259
I am trying to inject the MQQueueConnectionFactory defined as a JNDI resource into my spring configuration using @Resource. I am getting a ClassCastException while doing this. I am really confused on how to solve this. I am using JDK7 and spring 4.1.6.RELEASE. The MQ client is installed in a standard way and exported to tomcat classpath.
[ERROR] [TokenId=] [2015-05-29 21:33:53.496] [DispatcherServlet] - [Context initialization failed]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messagingConfig': Injection of resource dependencies failed; nested exception is org.
springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'java:comp/env/jms/SSAJMSQueueConnectionFactory' must be of type [javax.jms.ConnectionFactory], but
was actually of type [com.ibm.mq.jms.MQQueueConnectionFactory]
Upvotes: 0
Views: 200
Reputation: 956
When you see a ClassCastException which doesn't make sense, where you know for example that MQQueueConnectionFactory is an extension of ConnectionFactory, then it usually points to a classloader problem.
In most cases MQQueueConnectionFactory has been loaded with a different classloader to ConnectionFactory - this will cause a ClassCastException if you attempt to cast one to another even though you'd expect it to work.
Upvotes: 1