春季多笔交易经理问题 [英] spring multiple transaction manager issue
问题描述
我在两个单独的spring xml文件中定义了两个事务管理器,并且它们都已加载到spring上下文中
I have two transaction manager defined in two separate spring xml file, and both of them loaded into spring context
一个文件
<tx:annotation-driven transaction-manager="transactionManager1"/>
<bean id="transactionManager1"
class="org.springframework.jdbc.DataSourceTransactionManager">
...
</bean>
第二个文件
<tx:annotation-driven transaction-manager="transactionManager2"/>
<bean id="transactionManager2"
class="org.springframework.jdbc.DataSourceTransactionManager">
...
</bean>
如果我没有为以下服务指定任何限定符,那么将使用spring的事务管理器.
If I didn't indicate any qualifier for the below service, which transaction manager spring are going to use.
public class TransactionalService {
@Transactional
public void setSomething(String name) { ... }
@Transactional
public void doSomething() { ... }
}
推荐答案
查看
如果要连接的 You can omit the 由于您的事务管理器均未命名为 Since none of yours transaction managers are named 更新:解决您的修改问题.您可以指定要在 UPDATE: to address your modified question. You can specify which transaction manager to use on 但是,我发现您当前的设置存在一些问题: However I see several problems with your current setup: 使用不同的事务管理器两次定义 you define 没有明确提供事务管理器,应该使用哪个? without providing transaction manager explicitly, which one should be used? 我认为应该起作用的解决方案是一次定义 The solution I think should work is to define 这篇关于春季多笔交易经理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!PlatformTransactionManager
的bean名称具有名称transactionManager
,则可以省略<tx:annotation-driven/>
标记中的transaction-manager
属性.如果要依赖注入的PlatformTransactionManager
bean具有其他名称,则必须显式使用transaction-manager
属性[...]
transaction-manager
attribute in the <tx:annotation-driven/>
tag if the bean name of the PlatformTransactionManager
that you want to wire in has the name transactionManager
. If the PlatformTransactionManager
bean that you want to dependency-inject has any other name, then you have to use the transaction-manager
attribute explicitly [...]transactionManager
,因此必须为标记为@Transactional
的方法指定使用哪个事务管理器.transactionManager
, you must specify which transaction manager should be used for methods marked with @Transactional
.@Transactional
注释上使用的事务管理器(请参阅:@Transactional
annotation (see: @Transactional.value()
):@Transactional("transactionManager1")
//...
@Transactional("transactionManager2")
//...
<tx:annotation-driven/>
.我认为这样的配置无效
<tx:annotation-driven/>
twice with different transaction managers. I don't think such configuration is valid<tx:annotation-driven transaction-manager="transactionManager1"/>
并使用@Transactional
使用第一个管理器,使用@Transactional("transactionManager2")
使用第二个管理器.或相反.<tx:annotation-driven transaction-manager="transactionManager1"/>
once and use @Transactional
to use first manager and @Transactional("transactionManager2")
to use the second one. Or the other way around.