簡體   English   中英

在Spring JMS偵聽器中禁用事務管理

[英]Disabling Transaction Management in Spring JMS listener

我有一個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代碼,我們有( JmsAnnotationDrivenConfiguration ):

@Autowired(required = false)
private JtaTransactionManager transactionManager;

因此,現在僅需JtaTransactionManager類型恰好是JtaTransactionManager 我想你們兩個都是DataSourceTransactionManager

我確信這是正確的解決方案,只需要擔心XA tx-manager的自動配置即可。

對我來說,您可以在一個tx-manager bean上使用@Primary東西來解決問題。

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

也許僅僅排除 JmsAnnotationDrivenConfiguration就足夠了嗎?

如果仍然需要它,我只會看到一種解決方法:禁用JmsAnnotationDrivenConfiguration並手動配置@EnableJms ,繞過tx-manager問題,只是不按您的要求為DefaultJmsListenerContainerFactory配置它。

有關更多信息,請參見JmsAnnotationDrivenConfiguration源代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM