How to create bean of cachingconnectionfactory for publishing to tibco ems queue

1.1k Views Asked by At

I am trying to create a bean of cachingconnection factory for publishing to tibco ems queue . Below is the code base I have written to create bean.

    import javax.jms.JMSException;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.jms.connection.CachingConnectionFactory;
    import com.tibco.tibjms.TibjmsQueueConnectionFactory;
    
    @Configuration
    public class BeanConfiguration {
    
        @Autowired
        ConfigurationProperty config;
    
        @Bean
        public TibjmsQueueConnectionFactory tibcoConnection() {
            TibjmsQueueConnectionFactory tibco = new TibjmsQueueConnectionFactory();
            try {
                tibco.setServerUrl(config.getJmsUrl());
                tibco.setUserName(config.getTibcoUsername());
                tibco.setUserPassword(config.getTibcoPaswd());
                
            } catch (JMSException e) {
                e.printStackTrace();
            }
            return tibco;
        }
        @Bean
         public CachingConnectionFactory connectionFactory()
         {
            CachingConnectionFactory cachingConnection= new CachingConnectionFactory(tibcoConnection());
            cachingConnection.setSessionCacheSize(10);
            return cachingConnection;
         }
    
    }

Error is mentioned below.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jms.connection.CachingConnectionFactory]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.IllegalStateException: @Bean method BeanConfiguration.tibcoConnection called as bean reference for type [com.tibco.tibjms.TibjmsQueueConnectionFactory] but overridden by non-compatible bean instance of type [org.springframework.cloud.sleuth.instrument.messaging.LazyConnectionFactory]. Overriding bean of same name declared in: class path resource [config/BeanConfiguration.class]
1

There are 1 best solutions below

0
sachin kumar On

we need to create method for tibjmsQueueConnectionfactory and return type of cachingconnectionfactory should be updated to connectionfactory.

@Configuration public class BeanConfiguration {

@Autowired
ConfigurationProperty config;


private TibjmsQueueConnectionFactory tibcoConnection() {
    TibjmsQueueConnectionFactory tibco = new TibjmsQueueConnectionFactory();
    try {
        tibco.setServerUrl(config.getJmsUrl());
        tibco.setUserName(config.getTibcoUsername());
        tibco.setUserPassword(config.getTibcoPaswd());
        
    } catch (JMSException e) {
        e.printStackTrace();
    }
    return tibco;
}
@Bean
 public ConnectionFactory connectionFactory()
 {
    CachingConnectionFactory cachingConnection= new CachingConnectionFactory(tibcoConnection());
    cachingConnection.setSessionCacheSize(10);
    return cachingConnection;
 }

}