如何创建用于发布到tibco-ems队列的cachingconnectionfactory的bean



我正在尝试创建一个cachingconnection工厂的bean,用于发布到tibco-ems队列。下面是我为创建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;
}

}

下面提到了错误。

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]

我们需要为tibjmsQueueConnectionfactory创建方法,并且cachingconnectionfactory的返回类型应该更新为connectionfactory。

@配置公共类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;
}

}

最新更新