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 PlatformTransactionManager
s 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