一.开发环境:
springboot 2.2.12.RELEASE
mysql 8.0.2
postgres 13.2
二.安装maven依赖
- mysql 依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
- pg依赖
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
3.多数据源配置依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
三.添加配置信息
四.调用方式
mysql数据库的查询只需在 mapper添加注释@DS("master")