Using AbstractRoutingDataSource to dynamically change the database schema/catalog

三世轮回 提交于 2019-11-29 03:02:03

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/7960397/using-abstractroutingdatasource-to-dynamically-change-the-database-schema-catalo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!