java.lang.ClassCastException:无法将JedisConnectionFactory强制转换为ConnectionFactory

杰米·怀特

我不确定为什么方法“ connectionFactory”会返回JedisConnecionFactory的实例,而不是org.springframework.amqp.rabbit.connection.ConnectionFactory?

“ new RabbitTemplate(connectionFactory())”行中的以下异常(请参见下面的代码)

Feb 23, 2015 11:50:20 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
r:4.1.5.RELEASE]
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887) [catalina.jar:7.0.39]
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381) [catalina.jar:7.0.39]
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.39]
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.39]
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.39]
  at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0]
  at java.lang.Thread.run(Thread.java:744) [na:1.8.0]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.queue.MessageQueueSender]: Factory method 'messageQueueSender' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitTemplate' defined in class path resource [com/config/MessageQueueConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.core.RabbitTemplate]: Factory method 'rabbitTemplate' threw exception; nested exception is java.lang.ClassCastException: org.springframework.data.redis.connection.jedis.JedisConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  ... 23 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rabbitTemplate' defined in class path resource [com/config/MessageQueueConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.core.RabbitTemplate]: Factory method 'rabbitTemplate' threw exception; nested exception is java.lang.ClassCastException: org.springframework.data.redis.connection.jedis.JedisConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:322) ~[spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.rabbitTemplate(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at com.config.MessageQueueConfig.messageQueueSender(MessageQueueConfig.java:61) ~[MessageQueueConfig.class:na]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.CGLIB$messageQueueSender$1(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1$$FastClassBySpringCGLIB$$99208f13.invoke(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) ~[spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.messageQueueSender(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
  at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  ... 24 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.rabbit.core.RabbitTemplate]: Factory method 'rabbitTemplate' threw exception; nested exception is java.lang.ClassCastException: org.springframework.data.redis.connection.jedis.JedisConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  ... 45 common frames omitted
Caused by: java.lang.ClassCastException: org.springframework.data.redis.connection.jedis.JedisConnectionFactory cannot be cast to org.springframework.amqp.rabbit.connection.ConnectionFactory
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.connectionFactory(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at com.config.MessageQueueConfig.rabbitTemplate(MessageQueueConfig.java:75) ~[MessageQueueConfig.class:na]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.CGLIB$rabbitTemplate$2(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1$$FastClassBySpringCGLIB$$99208f13.invoke(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) ~[spring-context-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  at com.config.MessageQueueConfig$$EnhancerBySpringCGLIB$$68caa0b1.rabbitTemplate(<generated>) ~[spring-core-4.1.5.RELEASE.jar:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0]
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
  at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.1.5.RELEASE.jar:4.1.5.RELEASE]
  ... 46 common frames omitted

@配置类

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackages={"..."})
public class MessageQueueConfig {
    ..
    @Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(url);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        connectionFactory.setPort(port);
        return connectionFactory;
    }

    @Bean
    public RabbitTemplate rabbitTemplate() {
        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
        rabbitTemplate.setConnectionFactory(connectionFactory());
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
        rabbitTemplate.setRoutingKey("message.queue");
        return rabbitTemplate;
    }


}
加里·罗素

@ComponentScan必须找到另一个具有Redis连接工厂Bean且名称相同的配置文件,该配置文件将覆盖该文件。

您可以将DEBUG日志用于org.springframework; 解决豆子时,它发出大量原木。

另外,只需更改您的bean定义以使用其他bean名称: rabbitConnectionFactory()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

JMockit-java.lang.ClassCastException:无法将java.lang.String强制转换为Organization

来自分类Dev

java.lang.ClassCastException:无法将java.lang.String强制转换为[C

来自分类Dev

java.lang.ClassCastException:无法将Z强制转换为java.lang.String

来自分类Dev

java.lang.ClassCastException:无法将java.util.HashSet强制转换为Custom类

来自分类Dev

原因:java.lang.ClassCastException:无法将java.lang.Class强制转换为java.lang.reflect.ParameterizedType

来自分类Dev

休眠:java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

来自分类Dev

java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

来自分类Dev

休眠:java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

来自分类Dev

原因:java.lang.ClassCastException:无法将java.lang.Class强制转换为java.lang.reflect.ParameterizedType

来自分类Dev

java.lang.ClassCastException:[无法将B强制转换为play.twirl.api.Html

来自分类Dev

java.lang.ClassCastException:无法将DTOObject强制转换为DTOObject

来自分类Dev

无法将Java.lang.classcastexception linearlayout.layoutParams强制转换为framelayout.layoutparams

来自分类Dev

如何修复:java.lang.ClassCastException:无法将java.util.ArrayList强制转换为java.lang.Integer

来自分类Dev

java.lang.ClassCastException:无法将java.util.HashMap强制转换为java.lang.String

来自分类Dev

如何修复:java.lang.ClassCastException:无法将java.util.ArrayList强制转换为java.lang.Integer

来自分类Dev

Android HashMap java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.util.Map $ Entry

来自分类Dev

java.lang.ClassCastException:使用Univocity时无法将java.util.Date强制转换为java.lang.String

来自分类Dev

java.lang.ClassCastException:无法将java.util.Arrays $ ArrayList强制转换为java.lang.Integer

来自分类Dev

Hibernate HQL强制转换java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Long

来自分类Dev

java.lang.ClassCastException:无法将java.lang.String强制转换为com.parse.ParseUser

来自分类Dev

java.lang.ClassCastException:无法将javax.faces.component.StateHolderSaver强制转换为[Ljava.lang.Object;

来自分类Dev

java.lang.RuntimeException:java.lang.ClassCastException:java.lang.Long无法强制转换为java.lang.String

来自分类Dev

parse.com java.lang.ClassCastException:无法将java.util.HashMap强制转换为org.json.JSONObject

来自分类Dev

ClassCastException java.lang.Long无法强制转换为clojure.lang.IFn

来自分类Dev

SDN4 java.lang.ClassCastException:使用AttributeConverter时无法将java.lang.Integer强制转换为java.lang.Long

来自分类Dev

SDN4 java.lang.ClassCastException:使用AttributeConverter时无法将java.lang.Integer强制转换为java.lang.Long

来自分类Dev

java.lang.ClassCastException:无法将android.app.Application强制转换为roboguice.application.RoboApplication

来自分类Dev

获取java.lang.ClassCastException:无法将android.widget.FrameLayout $ LayoutParams强制转换为android.widget.RelativeLayout $ LayoutParams

来自分类Dev

Android java.lang.ClassCastException:无法将android.widget.LinearLayout $ LayoutParams强制转换为android.widget.AbsListView $ LayoutParams

Related 相关文章

  1. 1

    JMockit-java.lang.ClassCastException:无法将java.lang.String强制转换为Organization

  2. 2

    java.lang.ClassCastException:无法将java.lang.String强制转换为[C

  3. 3

    java.lang.ClassCastException:无法将Z强制转换为java.lang.String

  4. 4

    java.lang.ClassCastException:无法将java.util.HashSet强制转换为Custom类

  5. 5

    原因:java.lang.ClassCastException:无法将java.lang.Class强制转换为java.lang.reflect.ParameterizedType

  6. 6

    休眠:java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

  7. 7

    java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

  8. 8

    休眠:java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Double

  9. 9

    原因:java.lang.ClassCastException:无法将java.lang.Class强制转换为java.lang.reflect.ParameterizedType

  10. 10

    java.lang.ClassCastException:[无法将B强制转换为play.twirl.api.Html

  11. 11

    java.lang.ClassCastException:无法将DTOObject强制转换为DTOObject

  12. 12

    无法将Java.lang.classcastexception linearlayout.layoutParams强制转换为framelayout.layoutparams

  13. 13

    如何修复:java.lang.ClassCastException:无法将java.util.ArrayList强制转换为java.lang.Integer

  14. 14

    java.lang.ClassCastException:无法将java.util.HashMap强制转换为java.lang.String

  15. 15

    如何修复:java.lang.ClassCastException:无法将java.util.ArrayList强制转换为java.lang.Integer

  16. 16

    Android HashMap java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.util.Map $ Entry

  17. 17

    java.lang.ClassCastException:使用Univocity时无法将java.util.Date强制转换为java.lang.String

  18. 18

    java.lang.ClassCastException:无法将java.util.Arrays $ ArrayList强制转换为java.lang.Integer

  19. 19

    Hibernate HQL强制转换java.lang.ClassCastException:无法将java.lang.Integer强制转换为java.lang.Long

  20. 20

    java.lang.ClassCastException:无法将java.lang.String强制转换为com.parse.ParseUser

  21. 21

    java.lang.ClassCastException:无法将javax.faces.component.StateHolderSaver强制转换为[Ljava.lang.Object;

  22. 22

    java.lang.RuntimeException:java.lang.ClassCastException:java.lang.Long无法强制转换为java.lang.String

  23. 23

    parse.com java.lang.ClassCastException:无法将java.util.HashMap强制转换为org.json.JSONObject

  24. 24

    ClassCastException java.lang.Long无法强制转换为clojure.lang.IFn

  25. 25

    SDN4 java.lang.ClassCastException:使用AttributeConverter时无法将java.lang.Integer强制转换为java.lang.Long

  26. 26

    SDN4 java.lang.ClassCastException:使用AttributeConverter时无法将java.lang.Integer强制转换为java.lang.Long

  27. 27

    java.lang.ClassCastException:无法将android.app.Application强制转换为roboguice.application.RoboApplication

  28. 28

    获取java.lang.ClassCastException:无法将android.widget.FrameLayout $ LayoutParams强制转换为android.widget.RelativeLayout $ LayoutParams

  29. 29

    Android java.lang.ClassCastException:无法将android.widget.LinearLayout $ LayoutParams强制转换为android.widget.AbsListView $ LayoutParams

热门标签

归档