java 应用程序中事务_java – Spring – 是否可以在同一个应用程序中使用多个事务管理器?...

我是Spring的新手,我想知道是否可能在同一个应用程序中使用大量的事务管理器?

我有两个数据访问层 – 一个用于两个数据库。我想知道,你如何使用一个事务管理器为一个层和不同的事务管理器为其他层。我不需要在两个数据库之间执行事务。但我需要单独对每个数据库执行事务。我创建了一个图像来帮助概述我的问题:

这里是我的应用程序上下文配置:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">

class="org.springframework.orm.jpa.JpaTransactionManager">

下面是使用此配置的示例:

@Repository

public class JpaAccountRepository implements AccountRepository {

@PersistenceContext(unitName = "cheetahAccounts")

private EntityManager accountManager;

@Override

@Transactional

public Account findById(long id) {

Account account = accountManager.find(Account.class, id);

return account;

}

}

所以对于帐户存储库,我想使用实体管理器工厂,持久性单位设置为帐户。但是,对于我的BusinessData存储库,我想使用具有不同持久性单位的实体管理器工厂。由于我只能定义一个事务管理器bean,我如何使用不同的事务管理器为不同的存储库?

感谢任何帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值