简体   繁体   中英

Disabling Transaction Management in Spring JMS listener

I have a spring boot application as a Spring JMS listener. i have configured multiple datasource manager one for Oracle and another one for 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.

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. how could i achieve it or how can we disable jms transaction feature?

below are the annotation i have added on my main spring boot class. also i am using Spring Data repository

@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 ):

@Autowired(required = false)
private JtaTransactionManager transactionManager;

So, right now it requires only the bean which is exactly JtaTransactionManager by type. I guess both yours are DataSourceTransactionManager .

I'm sure that was correct fix to worry only about the XA tx-manager for auto-config.

Seems for me you can fix your issue with something like @Primary on one of your tx-manager beans.

But... Do you need a JMS Annotation support in your application at all?

Maybe it would be just enough to exclude JmsAnnotationDrivenConfiguration as well?

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.

See JmsAnnotationDrivenConfiguration source code for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM