【问题标题】:Disabling Transaction Management in Spring JMS listener在 Spring JMS 监听器中禁用事务管理
【发布时间】:2015-10-13 13:37:37
【问题描述】:

我有一个 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 Boot 类中添加的注释。我也在使用 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 版本。
  • 我正在使用 1.2.3.RELEASE 的 spring boot
  • 更新到最新的 1.2.6... JMS 自动配置的早期版本依赖于 PlatformTransactionManager 较新的版本特定的 JtaTransactionManager 因为它(通常)在那里进行交易是有意义的.
  • 将版本更改为最新版本后它工作了 :) 谢谢 Deinum

标签: spring-boot spring-jms


【解决方案1】:

查看我们拥有的当前 Spring Boot 代码 (JmsAnnotationDrivenConfiguration):

@Autowired(required = false)
private JtaTransactionManager transactionManager;

所以,现在它只需要按类型精确为JtaTransactionManager 的bean。我猜你们俩都是DataSourceTransactionManager

我确信这是正确的解决方法,只担心自动配置的 XA tx-manager。

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

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

也许仅仅排除 JmsAnnotationDrivenConfiguration 就足够了?

如果仍然需要它,我只看到一种解决方法:禁用JmsAnnotationDrivenConfiguration 并手动配置@EnableJms,绕过tx-manager 问题,只是不要按照您的要求为DefaultJmsListenerContainerFactory 配置它。

查看JmsAnnotationDrivenConfiguration源代码了解更多信息。

【讨论】:

  • 嗨,Artem,我刚刚将 Spring Boot 版本更改为最新版本,它停止给出该错误。在更改版本之前,我尝试过您提供的建议,例如尝试排除 JmsAnnotationDrivenConfiguration 但是当我将其添加到 @SpringBootApplication(exclude={}) 时没有 JmsAnnotationDrivenConfiguration.class。如果您让我知道如何按照您提到的那样手动配置 @EnableJms 或分享示例链接,那就太好了。
  • 1.不知道为什么你没有JmsAnnotationDrivenConfiguration,因为它是你上面的 StackTrace 的一部分。 2.请参考Spring手册@EnableJms:docs.spring.io/spring/docs/current/spring-framework-reference/…
猜你喜欢
  • 2015-02-28
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 2023-03-26
  • 1970-01-01
  • 2023-03-23
  • 2017-02-28
相关资源
最近更新 更多