implement dynamically datasource in spring data jpa

ε祈祈猫儿з 提交于 2021-01-12 06:21:08

问题


I have N Servers, N DBs and N configuration. see the scenario below

So, on every request , I need to access server and db based on configuration.

How can implement dynamically data source in spring data jpa?


回答1:


You can try AbstractRoutingDatasource provided by Spring since version 2.0.1. using which you can dynamically use appropriate data-source . For integration with Spring data JPA check this very good example. In your case since your configurations are in DB instead of properties file you would need to perform an extra first database lookup to get the appropriate database configuration and return appropriate data-source object.



来源:https://stackoverflow.com/questions/48825734/implement-dynamically-datasource-in-spring-data-jpa

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