[英]How to create bean of cachingconnectionfactory for publishing to tibco ems queue
我正在尝试创建一个用于发布到 tibco ems queue 的 cachingconnection 工厂的 bean。 下面是我编写的用于创建 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。
@Configuration 公共类 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.