Spring dynamically switches data sources
using Spring-related functions to dynamically switch data sources. It mainly uses the AbstractRouteDataSource provided by Spring. When performing a data read operation, query the specified read database, and when performing a write data operation, write data to the specified database.
1. Go to the relevant configuration files:
Spring-beans.xml:

2. Dynamic data source class DynamicDataSource:

3. Use ThreadLocal to set/get the data source type:

4. Code calling example: