Way One:
See blog https://www.cnblogs.com/AmbitiousMice/p/6027674.html
This way, you need to set the corresponding data source each time you call DAO.
Way two:
Configure the relevant DAO interface for the corresponding data source directly in the MyBatis configuration file (mapper.xml configuration file)
1. Database configuration file
Jdbc.driver=com.mysql.jdbc.driverjdbc.url=jdbc:mysql://duingold.mysql.rds.aliyuncs.com/pbossvisual? Characterencoding=utf-8jdbc.user=driverjdbc.password=driver123456pbossdb.jdbc.driver= com.mysql.jdbc.driverpbossdb.jdbc.url=jdbc:mysql://duingold.mysql.rds.aliyuncs.com/pbossdb?characterencoding= utf-8pbossdb.jdbc.user=driverpbossdb.jdbc.password=driver123456
Different data source configuration, note that different data sources corresponding to the Mapper.xml file is not the same. See the red box to ensure that the data source of the corresponding database is accessed when the interface is called.
2. Configuration of data source 1.
3. Configuration of Data source 2
4. Import the configuration files for two different data sources in the spring configuration file.
Spring+mybatis configuration of multiple data sources