Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用@EnableAutoConfiguration在spring启动应用程序中进行自定义事务管理_Spring_Transactions_Spring Boot_Spring Data - Fatal编程技术网

使用@EnableAutoConfiguration在spring启动应用程序中进行自定义事务管理

使用@EnableAutoConfiguration在spring启动应用程序中进行自定义事务管理,spring,transactions,spring-boot,spring-data,Spring,Transactions,Spring Boot,Spring Data,我正在spring引导应用程序中实现缓存内存的自定义事务管理(此时为simpleHashMap)。应用程序已经使用了由@EnableAutoConfiguration背后的一些魔术配置的JpaTransactionManager。这就是问题所在,因为应用程序试图加载两个PlatformTransactionManagers并抛出: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying be

我正在spring引导应用程序中实现缓存内存的自定义事务管理(此时为simple
HashMap
)。应用程序已经使用了由
@EnableAutoConfiguration
背后的一些魔术配置的
JpaTransactionManager
。这就是问题所在,因为应用程序试图加载两个
PlatformTransactionManager
s并抛出:

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.
事务管理器类:

@Component
public class KpiCacheTransactionManager extends AbstractPlatformTransactionManager{
...
}
我的事务管理器由以下配置类加载:

@Configuration
@EnableTransactionManagement
public class CacheTransactionConfiguration {

    @Bean(name = "cacheTransactionManager")
    public PlatformTransactionManager cacheTransactionManager() {
        return new CacheTransactionManager();
    }     
}
主应用程序使用以下配置运行:

@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{
}
我已经找到了一些可能的解决方案(
@Primary
注释,管理器名称,…),但我不知道如何使用
@EnableAutoConfiguration
在现有配置上设置它,如何用我自己的设置覆盖
JpaTransactionManager
的默认配置


Env:Java8、SpringBoot1.2.1、Spring4.1.4、SpringDataJPA1.7.2、Hibernate4.3.7、ApacheTomcat8.0.15这实际上是SpringFramework 4.1.4中的一个bug。我们即将发布4.1.5,但同时请降级至4.1.3


请参见

谢谢您的回答。如何为spring boot设置spring版本?我尝试在pom.xml中设置为in,如下所述:[,但应用程序仍以版本4.1.4运行(来自日志文件“running with Spring Boot v1.2.1.RELEASE,Spring v4.1.4.RELEASE”)仅当您使用
spring boot starter父项作为父项时,这才有效。您可能正在使用scope
import
中的
spring boot dependencies
集成启动。只需在启动之前添加
spring framework bom
和scope
import
。使用此设置,我可以运行我的应用程序使用了spring 4.1.3,但它引发了相同的异常。然而,我已使用@Primary将JpaTransactionManager bean的显式创建添加到CacheTransactionConfiguration中,异常消失。现在,我对transactionmanager本身存在问题-它在JUnit测试(SpringJUnit4ClassRunner)中工作,但在应用程序中被忽略(不调用cacheTransactionManager方法),但这是独立线程的另一个问题。