1:pom.xml
<!--多数据源插件-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
</dependency>
2:JAVA_HOME\jre\lib\security\java.security 配置里的 jdk.tls.disabledAlgorithms 的配置 TLSv1, TLSv1.1 删除
C:\Program Files\Java\jre1.8.0_341\lib\security\java.security 也要删除!!!
3:多数据源连接配置
datasource:
dynamic:
# 指定默认数据源
primary: master
# true:找不到数据源报错,false:找不到数据源则使用数据源
strict: false
datasource:
master:
username: root
password: root
url: jdbc:mysql://192.168.1.899:3306/mall?SSL=false
driver-class-name: com.mysql.cj.jdbc.Driver
slave:
username: sa
password: 123
url: jdbc:sqlserver://192.168.0.998:1433;DatabaseName=kingsun
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
autoconfigure:
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
4:使用数据源
wx小程序搜索磁力种子王,累了就去放松下吧!
@DS("slave")