2
votes

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);
    }
}
1
Which spring boot version are you using.M. Deinum
i am using 1.2.3.RELEASE of spring bootSomnath Goswami
Update to the most recent 1.2.6... Earlier versions of the JMS auto configuration relied on the PlatformTransactionManager newer versions the specific JtaTransactionManager as it (generally) makes sense to have transactions there.M. Deinum
it worked after changing version to latest release :) Thanks DeinumSomnath Goswami

1 Answers

0
votes

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.