加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring多个事务管理器问题

发布时间:2020-12-15 01:37:03 所属栏目:大数据 来源:网络整理
导读:我有两个事务管理器在两个单独的spring xml文件中定义,并且它们都加载到spring上下文中 文件一 文件二 如果我没有为下面的服务指出任何限定符,那么将使用哪个事务管理器spring. public class TransactionalService { @Transactional public void setSomethin

我有两个事务管理器在两个单独的spring xml文件中定义,并且它们都加载到spring上下文中

文件一

   

文件二

 

如果我没有为下面的服务指出任何限定符,那么将使用哪个事务管理器spring.

public class TransactionalService {

    @Transactional
    public void setSomething(String name) { ... }

    @Transactional
    public void doSomething() { ... }
}
最佳答案
从官方文档中查看11.5.6 Using @Transactional

You can omit the transaction-manager attribute in the 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的方法.

更新:解决您修改过的问题.您可以指定在@Transactional注释上使用哪个事务管理器(请参阅:@Transactional.value()):

@Transactional("transactionManager1")
//...

@Transactional("transactionManager2")
//...

但是我发现您当前的设置有几个问题:

>你定义< tx:annotation-driven />两次与不同的交易经理.我不认为这样的配置是有效的
>没有明确提供事务管理器,应该使用哪一个?

我认为应该解决的解决方案是定义< tx:annotation-driven transaction-manager =“transactionManager1”/>一次并使用@Transactional使用第一个管理器和@Transactional(“transactionManager2”)来使用第二个管理器.或者相反.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读