<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
spring:
# 配置数据源信息
datasource:
type: com.zaxxer.hikari.HikariDataSource
dynamic:
#设置默认的数据源或者数据源组,默认值即为master
primary: master
strict: false
datasource:
#这里采用了配置文件取值的方式,可以直接替换为数据库连接
master:
url: jdbc:mysql://ip:端口/databsae1
username: 用户名
password: 密码
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
pool-name: 连接池名称
max-pool-size: 20
min-idle: 5
idle-timeout: 60000
max-lifetime: 300000
connection-timeout: 30000
validation-timeout: 5000
connection-test-query: select 'x'
@Mapper
public interface TestInfoMapper extends BaseMapper<TestInfo> {
@DS("master")
List<TestInfo> select(Integer param);
}