2013-05-22 40 views
0

我在一起運行rabbitmq和jms Spring Project時出現以下錯誤。org.springframework.jms.connection.CachingConnectionFactory無法轉換爲org.springframework.amqp.rabbit.connection.ConnectionFactory

錯誤osweb.context.ContextLoader - 上下文初始化失敗 org.springframework.beans.factory.BeanCreationException:錯誤 建立在類路徑定義名稱 'rabbitTemplate' 豆 資源[COM/THYS /米歇爾斯/ service_core/amqp/AmqpConfiguration.class]: bean實例化失敗;嵌套的異常是 org.springframework.beans.factory.BeanDefinitionStoreException: 工廠方法[公共 org.springframework.amqp.rabbit.core.RabbitTemplate com.thys.michels.service_core.amqp.AmqpConfiguration.rabbitTemplate()] 扔例外;嵌套的例外是java.lang.ClassCastException: org.springframework.jms.connection.CachingConnectionFactory不能 投地org.springframework.amqp.rabbit.connection.ConnectionFactory

產生的原因:java.lang.ClassCastException: 組織.springframework.jms.connection.CachingConnectionFactory不能 投地org.springframework.amqp.rabbit.connection.ConnectionFactory

任何建議,爲什麼?

+0

您使用的是spring,rabbitmq的哪個版本?你能發佈你的配置嗎? – willome

+0

配置很長,希望這有助於: 3.2.2.RELEASE \t org.springframework.amqp \t 彈簧AMQP \t 1.0.0.RELEASE \t org.springframework.amqp \t 彈簧兔 \t 1.0.0.RELEASE

+0

和你的彈簧配置? – willome

回答

0

我的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的名稱和它的工作。

相關問題