Spring Cloud Sleuth集成ActiveMQ时Bean类型不匹配问题求助
我长期在寻找该问题的解决方案,恳请各位提供思路!
错误信息
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'routerConnectionFactory' defined in class path resource [com/CONFIDENTIAL/event/processor/configuration/EventsConfiguration.class]: Unsatisfied dependency expressed through method 'routerConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'actionRouterConnectionFactory' is expected to be of type 'org.apache.activemq.ActiveMQConnectionFactory' but was actually of type 'org.springframework.cloud.sleuth.instrument.messaging.LazyTopicConnectionFactory'
代码片段
@Bean(name = "routerConnectionFactory") @Primary public CachingConnectionFactory routerConnectionFactory(ActiveMQConnectionFactory actionRouterConnectionFactory ){ CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.setTargetConnectionFactory(actionRouterConnectionFactory); return cachingConnectionFactory; } @Bean public ActiveMQConnectionFactory actionRouterConnectionFactory( @Value("${confidential.gateway.message.broker.url}") String brokerURL, @Value("${confidential.router.message.broker.user.name}") String userName, @Value("${confidential.router.message.broker.user.password}") String password, @Value("true") Boolean alwaysSyncSend, RedeliveryPolicy defaultEntry, @Value("${shared.amq.keystore.path:#{null}}") String keyStorePath, @Value("${shared.amq.keystore.password:#{null}}") String keyStorePassword) throws Exception { ActiveMQSslConnectionFactory targetConnectionFactory= new ActiveMQSslConnectionFactory(); targetConnectionFactory.setBrokerURL(brokerURL); targetConnectionFactory.setUserName(userName); targetConnectionFactory.setPassword(password); if(!StringUtils.isEmpty(keyStorePath) && !StringUtils.isEmpty(keyStorePassword)){ targetConnectionFactory.setTrustStore(keyStorePath); targetConnectionFactory.setTrustStorePassword(keyStorePassword); } targetConnectionFactory.setAlwaysSyncSend(alwaysSyncSend); targetConnectionFactory.setRedeliveryPolicy(defaultEntry); return targetConnectionFactory; }
依赖版本
- spring-cloud-sleuth-core : 2.2.6.RELEASE
- spring-cloud-sleuth-zipkin : 2.2.6.RELEASE
- ActiveMQ相关依赖(broker、camel、client、jms-pool等): 5.15.13
- 其他Spring Boot及相关依赖: 2.2.6.RELEASE
已尝试操作
已参考多篇技术文章(包括Stack Overflow),也尝试禁用Sleuth,但问题仍未解决。
求解决线索
内容的提问来源于stack exchange,提问作者Harsh

