如何解决如何创建缓存连接工厂的 bean 以发布到 tibco ems 队列
我正在尝试创建一个用于发布到 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 创建方法,并且缓存connectionfactory的返回类型应该更新为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;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。