问题描述
我正尝试使用此网络研讨会
我想知道如何通过spring来配置多个数据源,也许是通过使用属性文件并基于租户id从spring上下文中获取数据源.
I wanted to know how would I configure multiple data sources via spring perhaps by using properties files and get the data sources from the spring context based on tenant id.
更重要的是,尽管我希望能够配置支持此多租户功能的自定义连接提供程序实现,以供Hibernate使用,而不是默认使用的注入的ConnectionProvider
.
More importantly, though I want to be able to configure my custom connection provider implementation that supports this multitenancy feature to be used by Hibernate instead of the injected ConnectionProvider
that it uses by default.
我如何实现这一目标.
推荐答案
使用AbstractRoutingDataSource
.请参阅位于@ 使用多个数据源时,Spring中出现多个实体管理器问题..
Use the AbstractRoutingDataSource
. See my answer located @ Multiple Entity Manager issue in Spring when using more than one datasource.
这篇关于如何在Hibernate中为多租户配置多个数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!