Jayant Kokitkar
Jayant Kokitkar

Reputation: 65

How to deal with the build error while using sping cloud sleuth?

I am working on one project which uses java messaging service(JMS) and it uses activemq connection factory implementation for it. Now I want to use spring-cloud-starter-sleuth to instrument the application for tracing. But I am not able to do it as I am getting following exception while starting the application-

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]

Below are the connection factory beans that I use :

// ***** 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;
}

I have tried all the release versions of spring-cloud-starter-sleuth as well as latest version but still getting same issue. How should I deal with this issue?

Updated: As per one of the comment in https://github.com/spring-cloud/spring-cloud-sleuth/issues/1324 we need to disable the jms tracing as mentioned via the property and instrument the connection manually as presented in the Brave's readme https://github.com/openzipkin/brave/tree/master/instrumentation/jms But still I don't get sufficient info from brave's readme. How can I use brave instrumentation manually in my spring boot application?

Upvotes: 1

Views: 1520

Answers (1)

Mohamed Ali RACHID
Mohamed Ali RACHID

Reputation: 3297

You get this error because spring-cloud-starter-sleuth is defining a JmsTemplate bean as well.

If you do not need the tracing of JMS you can disable it by adding this property to you properties file :

spring.sleuth.messaging.jms.enabled = false

After re-running your app the error will disappear.

Upvotes: 7

Related Questions