[英]Disabling Transaction Management in Spring JMS listener
I have a spring boot application as a Spring JMS listener. 我有一个Spring Boot应用程序作为Spring JMS侦听器。 i have configured multiple datasource manager one for Oracle and another one for DB2 .
我已经为Oracle配置了多个数据源管理器,为DB2配置了另一个。
whenever i am starting app ,jms listener container is looking for a transaction manager bean and giving below error as it find two bean. 每当我启动应用程序时,jms侦听器容器都会查找事务管理器bean,并在发现两个bean时给出以下错误。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jms.JmsAnnotationDrivenConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.PlatformTransactionManager org.springframework.boot.autoconfigure.jms.JmsAnnotationDrivenConfiguration.transactionManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: db2TransactionManager,oracleTransactionManager
i dont want to maintain JMS transaction. 我不想维护JMS事务。 how could i achieve it or how can we disable jms transaction feature?
我如何实现它或如何禁用JMS事务功能?
below are the annotation i have added on my main spring boot class. 以下是我在主Spring Boot类中添加的注释。 also i am using Spring Data repository
我也在使用Spring Data存储库
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})
@ComponentScan(basePackages = "com.deere.oracledataupdate.*")
//@EnableJpaRepositories(basePackages ="com.deere.oracledataupdate.dao.springdata")
@EntityScan(basePackages = "com.deere.oracledataupdate.*")
@PropertySource({ "classpath:application-${IafConfigSuffix}.properties" })
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Looking to the current Spring Boot code we have ( JmsAnnotationDrivenConfiguration
): 查看当前的Spring Boot代码,我们有(
JmsAnnotationDrivenConfiguration
):
@Autowired(required = false)
private JtaTransactionManager transactionManager;
So, right now it requires only the bean which is exactly JtaTransactionManager
by type. 因此,现在仅需
JtaTransactionManager
类型恰好是JtaTransactionManager
。 I guess both yours are DataSourceTransactionManager
. 我想你们两个都是
DataSourceTransactionManager
。
I'm sure that was correct fix to worry only about the XA
tx-manager for auto-config. 我确信这是正确的解决方案,只需要担心
XA
tx-manager的自动配置即可。
Seems for me you can fix your issue with something like @Primary
on one of your tx-manager beans. 对我来说,您可以在一个tx-manager bean上使用
@Primary
东西来解决问题。
But... Do you need a JMS Annotation support in your application at all? 但是...您的应用程序中是否需要JMS注释支持?
Maybe it would be just enough to exclude JmsAnnotationDrivenConfiguration
as well? 也许仅仅排除
JmsAnnotationDrivenConfiguration
就足够了吗?
If need it anyway, I see only one way to fix it: disable JmsAnnotationDrivenConfiguration
and configure @EnableJms
manually, bypassing the tx-manager issue and just don't configure it for the DefaultJmsListenerContainerFactory
as you request. 如果仍然需要它,我只会看到一种解决方法:禁用
JmsAnnotationDrivenConfiguration
并手动配置@EnableJms
,绕过tx-manager问题,只是不按您的要求为DefaultJmsListenerContainerFactory
配置它。
See JmsAnnotationDrivenConfiguration
source code for more information. 有关更多信息,请参见
JmsAnnotationDrivenConfiguration
源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.