使用AbstractRoutingDataSource动态更改数据库模式/目录 [英] Using AbstractRoutingDataSource to dynamically change the database schema/catalog

查看:287
本文介绍了使用AbstractRoutingDataSource动态更改数据库模式/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据本文,您可以使用AbstractRoutingDataSource从Spring框架动态更改应用程序使用的数据源。



但是,使用的数据源由配置而不是编程方式定义。是否有一种方法来配置要在运行时使用的数据源?



此解决方案的可扩展性,即数据源数量的限制? p>

谢谢!

解决方案

我已经为30个数据源实现了这种方法,目前正在生产环境中运行,没有任何问题。如果你使用JPA,你可以看看我的配置:



动态数据源路由


According to this article, you can use the AbstractRoutingDataSource from Spring Framework to dynamically change the data source used by the application.

However, the data sources used are defined by configuration, instead of programmatically. Is there a way of configuring the data sources to be used at runtime?

How scalable is this solution, i.e., what are the limitations in number of data sources?

Thanks!

解决方案

I have implemented this approach for 30 datasources and they are currently running in a Production environment without any issues. If you are using JPA you can have a look at my config:

dynamic-datasource-routing

这篇关于使用AbstractRoutingDataSource动态更改数据库模式/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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