ClassCastException javax.naming.Reference cannot be cast to javax.jms.ConnectionFactory
In a nustshell, the javax.naming.Reference represents an object external to a naming system that is referred to by an object in the naming system. A Reference contains an address for retrieving the object from its naming system.
Solving the ClassCastException error
This error typically happens when you are trying to lookup a component like a JMS ConnectionFactory or a Datasource from the JNDI. The most frequent reason is that you are missing some libraries in the classpath.
Therefore, check which is the resource that you are not able to cast. If it is a javax.jmx.ConnectionFactory, for example, you might need the JMS broker implementation in your classpath.
For example, if you are connecting to IBM MQ Broker, you might need in your classpath the Client libraries:
<dependency> <groupId>com.ibm.mq</groupId> <artifactId>com.ibm.mq.allclient</artifactId> <version>9.3.0.0</version> </dependency>