gpt4 book ai didi

spring-boot - 在 Spring JMS 监听器中禁用事务管理

转载 作者:行者123 更新时间:2023-12-05 07:53:06 25 4
gpt4 key购买 nike

我有一个 Spring Boot 应用程序作为 Spring JMS 监听器。我已经配置了多个数据源管理器,一个用于 Oracle,另一个用于 DB2。

每当我启动应用程序时,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

我不想维护 JMS 事务。我怎样才能实现它或者我们怎样才能禁用 jms 事务功能?

下面是我在主要的 spring 引导类中添加的注释。我也在使用 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);
}
}

最佳答案

查看当前的 Spring Boot 代码(JmsAnnotationDrivenConfiguration):

@Autowired(required = false)
private JtaTransactionManager transactionManager;

所以,现在它只需要类型完全是 JtaTransactionManager 的 bean。我猜你的都是 DataSourceTransactionManager

我确信这是正确的解决方案,只需要担心用于自动配置的 XA tx-manager。

在我看来,您可以在您的一个 tx-manager bean 上使用 @Primary 之类的东西来解决您的问题。

但是...您的应用程序中是否需要 JMS 注释支持?

也许 exclude JmsAnnotationDrivenConfiguration 就足够了吗?

如果无论如何需要它,我只看到一种修复它的方法:禁用 JmsAnnotationDrivenConfiguration 并手动配置 @EnableJms,绕过 tx-manager 问题,只是不要根据您的要求为 DefaultJmsListenerContainerFactory 配置它。

有关详细信息,请参阅JmsAnnotationDrivenConfiguration 源代码。

关于spring-boot - 在 Spring JMS 监听器中禁用事务管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33104177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com