引入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.2.1</version>
</dependency>
修改配置
spring:
datasource:
druid:
initial-size: 10
max-active: 100
min-idle: 3
max-wait: 5000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 100
dynamic:
primary: "db1"
datasource:
db1:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://host1:3306/warehouse_mgmt?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
password: 12345678
username: root
db2:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://host2:3306/zkeco?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
password: 123456
username: root
排除默认数据源加载
启动类注解:
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
本科计算机bi-ye-she-ji辅导,远程安装运行+部署,欢迎各位小伙伴打扰~企鹅号:298-150-5753