spring 多个事务管理器,运行时选择一个 [英] Multiple transaction managers in spring and select one at runtime

查看:43
本文介绍了spring 多个事务管理器,运行时选择一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于每个客户端,我有单独的数据库,但每个客户端的业务逻辑和表都是相同的.我想要每个客户端的公共服务和 dao 层.在 dao 中,我根据登录的用户客户端选择数据源.在 @Transactional 中,我必须传递事务管理器的 bean id.如何使用@Transactional注解制作公共服务层.

For each client, I have separate databases but business logic and tables are same for each client. I want common service and dao layer for each client. In dao, I select datasource based on logged user client. In @Transactional, I have to pass bean id of transaction manager. How to make common service layer with @Transactional annotation.

同样的问题在这里

  1. 多个事务管理器 - 在运行时 - Spring

在运行时选择多个事务管理器

但没人回复

推荐答案

您不需要在多个事务管理器之间进行配置和切换来实现您的最终目标.而是使用 Spring 提供的 org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource 机制.

You do not need to configure and switch between multiple transaction managers to accomplish your end goal. Instead use the Spring provided org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource mechanism.

可以在此处找到详细示例:

Detailed examples can be found here :

  1. https://spring.io/blog/2007/01/23/动态数据源路由/
  2. http://howtodoinjava.com/spring/spring-orm/spring-3-2-5-abstractroutingdatasource-example/

这篇关于spring 多个事务管理器,运行时选择一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆