2
votes

I'm implementing custom transaction management for a cache memory (simple HashMap at this time) in a spring boot application. The application already uses JpaTransactionManager configured by some magic behind @EnableAutoConfiguration. And this is problem, because application tries to load two PlatformTransactionManagers and throws:

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: cacheTransactionManager,transactionManager.

Transaction manager class:

@Component
public class KpiCacheTransactionManager extends AbstractPlatformTransactionManager{
...
}

My transaction manager is loaded by this configuration class:

@Configuration
@EnableTransactionManagement
public class CacheTransactionConfiguration {

    @Bean(name = "cacheTransactionManager")
    public PlatformTransactionManager cacheTransactionManager() {
        return new CacheTransactionManager();
    }     
}

Main application is runned using this configuration:

@Configuration("MyApplication")
@EnableAutoConfiguration
@EntityScan("com.foo.bar")
@EnableJpaRepositories("com.foo.bar")
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@ComponentScan("com.foo.bar")
@ImportResource({...})
public class MyApplication extends SpringBootServletInitializer{
}

I've found some possible solutions (@Primary annotation, manager names,... ), but I don't know how to set this on existing configuration with @EnableAutoConfiguration, how to override the default configuration for JpaTransactionManager with my own.

Env: Java 8, Spring Boot 1.2.1, Spring 4.1.4, Spring data JPA 1.7.2, Hibernate 4.3.7, Apache Tomcat 8.0.15

1

1 Answers

2
votes

This is actually a bug in Spring Framework 4.1.4. We are releasing 4.1.5 soon but in the meantime please downgrade to 4.1.3.

See SPR-12577