Spring 数据与 JPA (mySQL) - 动态改变数据源
Spring data with JPA (mySQL) - changing the data source dynamically
我们正在使用具有单个数据源 (MySQL) 的 spring MVC Web 应用程序。
我们现在有一个新要求:
我们希望我们的一些客户将使用机器#1 的 MySQL 数据库作为他们的数据源。
其他客户端应使用机器#2 的 MySQL 数据库作为其数据源。
这两个数据源在结构上完全相同,只是数据不同。
这两台不同的机器包含两个不同客户的数据库,出于明显的原因,这两个客户不想共享同一个数据库。
这可能只需要对我们的代码库进行最小的更改吗?
The general idea is that a routing DataSource acts as an intermediary
- while the ‘real’ DataSource can be determined dynamically at runtime based upon a lookup key.
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/
我们正在使用具有单个数据源 (MySQL) 的 spring MVC Web 应用程序。 我们现在有一个新要求:
我们希望我们的一些客户将使用机器#1 的 MySQL 数据库作为他们的数据源。
其他客户端应使用机器#2 的 MySQL 数据库作为其数据源。
这两个数据源在结构上完全相同,只是数据不同。
这两台不同的机器包含两个不同客户的数据库,出于明显的原因,这两个客户不想共享同一个数据库。
这可能只需要对我们的代码库进行最小的更改吗?
The general idea is that a routing DataSource acts as an intermediary - while the ‘real’ DataSource can be determined dynamically at runtime based upon a lookup key.
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/