无法将org.springframework.jms.connection.CachingConnectionFactory转换为org.springframework.amqp.rabbit.connection.ConnectionFactory
当我同时运行rabbitmq和jms Spring项目时,出现以下错误 错误o.s.web.context.ContextLoader-上下文初始化失败 org.springframework.beans.factory.BeanCreationException:错误 创建名为“rabbitmplate”的bean(在类路径中定义) 资源[com/thys/michels/service_core/amqp/AmqpConfiguration.class]: bean实例化失败;嵌套异常是 org.springframework.beans.factory.BeanDefinitionStoreException: 工厂法[公开] org.springframework.amqp.rabbit.core.RabbitTemplate com.thys.michels.service_core.amqp.AmqpConfiguration.rabbitemplate()] 抛出异常;嵌套异常为java.lang.ClassCastException: 无法创建org.springframework.jms.connection.CachingConnectionFactory 转换为org.springframework.amqp.rabbit.connection.ConnectionFactory 原因:java.lang.ClassCastException: 无法创建org.springframework.jms.connection.CachingConnectionFactory 转换为org.springframework.amqp.rabbit.connection.ConnectionFactory无法将org.springframework.jms.connection.CachingConnectionFactory转换为org.springframework.amqp.rabbit.connection.ConnectionFactory,spring,jms,rabbitmq,Spring,Jms,Rabbitmq,当我同时运行rabbitmq和jms Spring项目时,出现以下错误 错误o.s.web.context.ContextLoader-上下文初始化失败 org.springframework.beans.factory.BeanCreationException:错误 创建名为“rabbitmplate”的bean(在类路径中定义) 资源[com/thys/michels/service_core/amqp/AmqpConfiguration.class]: bean实例化失败;嵌套异常是 o
有什么建议吗?我的JMS和RabbitMQ类都有一个名为connectionFactory的connectionFactory类,因此JMS的connectionFactory被用于RabbitMQ配置的初始化 JMS类
@Bean
public ConnectionFactory connectionFactory() throws Exception {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(environment.getProperty("jms.broker.url"));
return new CachingConnectionFactory(activeMQConnectionFactory);
}
RabbitMQ类
@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;
}
刚刚更改了connectionFactory名称,它就工作了。您使用的是哪种版本的spring、rabbitmq?你也可以发布你的配置吗?配置很长,希望这有帮助:3.2.2.RELEASE org.springframework.amqp spring amqp 1.0.0.RELEASE org.springframework.amqp spring rabbit 1.0.0.RELEASE和您的spring配置?JMS Bean:@Bean public ConnectionFactory ConnectionFactory()引发异常{ActiveMQConnectionFactory ActiveMQConnectionFactory=new ActiveMQConnectionFactory();ActiveMQConnectionFactory.setBrokerURL(environment.getProperty(“jms.broker.url”);返回新的CachingConnectionFactory(ActiveMQConnectionFactory);}