Reputation: 781
I am getting the following error when I run rabbitmq and jms Spring Project together.
ERROR o.s.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitTemplate' defined in class path resource [com/thys/michels/service_core/amqp/AmqpConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.amqp.rabbit.core.RabbitTemplate com.thys.michels.service_core.amqp.AmqpConfiguration.rabbitTemplate()] threw exception; nested exception is java.lang.ClassCastException: org.springframework.jms.connection.CachingConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
Caused by: java.lang.ClassCastException: org.springframework.jms.connection.CachingConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
Any suggestions why?
Upvotes: 0
Views: 4045
Reputation: 781
Both my JMS and RabbitMQ class had a connectionFactory class called connectionFactory and so the connectionfactory for JMS was used initialized for RabbitMQ config.
JMS class
@Bean
public ConnectionFactory connectionFactory() throws Exception {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(environment.getProperty("jms.broker.url"));
return new CachingConnectionFactory(activeMQConnectionFactory);
}
RabbitMQ class
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setUsername(environment.getProperty("amqp.broker.username"));
cachingConnectionFactory.setPassword(environment.getProperty("amqp.broker.password"));
cachingConnectionFactory.setHost(environment.getProperty("amqp.broker.host"));
cachingConnectionFactory.setPort(environment.getProperty( "amqp.broker.port", Integer.class));
// cachingConnectionFactory.setPort(60705);
return cachingConnectionFactory;
}
just changed the connectionFactory names and it worked.
Upvotes: 2