【问题标题】:How to deal with the build error while using sping cloud sleuth?使用spring cloud sleuth时如何处理构建错误?
【发布时间】:2022-12-20 04:34:24
【问题描述】:

我正在开发一个使用 java 消息服务 (JMS) 的项目,它使用 activemq 连接工厂实现。 现在我想使用 spring-cloud-starter-sleuth 来检测应用程序以进行跟踪。但是我无法做到这一点,因为我在启动应用程序时遇到异常 -

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.pool.PooledConnectionFactory]: Factory method 'pooledConnectionFactory' threw exception; nested exception is java.lang.IllegalStateException: @Bean method JmsConfiguration.senderActiveMQConnectionFactory called as bean reference for type [org.apache.activemq.ActiveMQConnectionFactory] but overridden by non-compatible bean instance of type [org.springframework.cloud.sleuth.instrument.messaging.LazyTopicConnectionFactory]. Overriding bean of same name declared in: class path resource [com/demo/appconfig/JmsConfiguration.class]

以下是我使用的连接工厂 bean:

// ***** sender configuration
    @Bean
    public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory =
                new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(brokerUrl);
        activeMQConnectionFactory.setUseAsyncSend(useAsyncSend);
        return activeMQConnectionFactory;
    }  

 @Bean
    public PooledConnectionFactory pooledConnectionFactory() {
        return new org.apache.activemq.pool.PooledConnectionFactory(
                senderActiveMQConnectionFactory());
    }



@Bean
public JmsTemplate jmsTemplate() {
         
       JmsTemplate jmsTemplate = new JmsTemplate(pooledConnectionFactory());
    
    jmsTemplate.setMessageConverter(messageConverter());
    return jmsTemplate;
}

我已经尝试了spring-cloud-starter-sleuth 的所有发行版本以及最新版本,但仍然遇到同样的问题。我该如何处理这个问题?

更新:根据https://github.com/spring-cloud/spring-cloud-sleuth/issues/1324中的评论之一 我们需要通过属性禁用 jms 跟踪,并手动检测连接,如 Brave 的自述文件https://github.com/openzipkin/brave/tree/master/instrumentation/jms 所示 但我仍然没有从 brave 的自述文件中获得足够的信息。如何在我的 spring boot 应用程序中手动使用 brave instrumentation?

【问题讨论】:

    标签: spring spring-boot spring-jms spring-cloud-sleuth zipkin


    【解决方案1】:

    您收到此错误是因为 spring-cloud-starter-sleuth 也定义了 JmsTemplate bean。

    如果您不需要 JMS 的跟踪,您可以通过将此属性添加到您的属性文件来禁用它:

    spring.sleuth.messaging.jms.enabled = false

    重新运行您的应用程序后,错误将消失。

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2020-05-28
      • 1970-01-01
      • 2021-09-06
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 2022-05-24
      • 1970-01-01
      相关资源
      最近更新 更多