具有相同实体和仓库的多个数据源 [英] Multiple Data Sources with same entity and repo

查看:107
本文介绍了具有相同实体和仓库的多个数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在从事我的Spring Boot项目需要 利用同一数据库服务器中的多个数据源或架构.我有 在中找到了一些讲授多个数据源配置的教程 弹簧启动,其中实体foo存在于数据源A中,而bar存在于 数据源B在下面.

Currently working on a project where my Spring Boot project needs to leverage multiple data sources or schema in the same DB server. I have found several tutorials that teach multiple data source configuration in spring boot where entity foo exists in DataSource A and bar exists in DataSource B namely below.,

https://scattercode.co. uk/2016/01/05/multiple-databases-with-spring-boot- 和spring-data-jpa/ https://scattercode.co.uk/2013/11 /18/spring-data-multiple-databases/ https://medium.com /@ joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7

https://scattercode.co.uk/2016/01/05/multiple-databases-with-spring-boot- and-spring-data-jpa/ https://scattercode.co.uk/2013/11/18/spring-data-multiple-databases/ https://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7

但是我的用例是实体foo和bar存在于多个架构中,我想使用单个实体和存储库来访问所有架构.数据并未在所有架构中复制,而是在它们之间划分.

But my use case is that entities foo and bar are present in multiple schema and I want to use a single entity and repository to access all schema.Data is not replicated in all schema.It is divided among them.

因此,如果我需要搜索用户John Doe,则必须仔细阅读Schema 1和 如果找不到他,请转到下一个模式.

So if I need to search for User John Doe I have to go through Schema 1 and if I don't find him, move onto the next schema.

我已经尝试了以上所有教程(即使它们与我的教程不一致) 用例),希望我可以破解它以使其能够像 概念证明. 我也研究了AbstractRoutingDataSource ( http://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/

I have tried all the above tutorials(even though they don't line up with my use case) with the hope that I could hack it to get it working just as a proof of concept. I have also looked into AbstractRoutingDataSource (http://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/ , http://kimrudolph.de/blog/spring-datasource-routing) and MultiTentancy but both of these talk about having access to a single schema at any point in time. I just need some guidance or link to follow and get this accomplished.

谢谢.

推荐答案

通过使用 https://github.com/wmeints/spring-multi-tenant-demo .

感谢@surya的推荐.

Thanks @surya for your recommendation.

这篇关于具有相同实体和仓库的多个数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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