1、添加 aop 、sharding-jdbc 依赖
<!--aop->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--sharding-jdbc-->
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
2、yml文件配置
# 数据源
sharding.jdbc.datasource.names=xxx-pub,xxx-ha,xxx-sd,xxx-zj,xxx-hq,xxx-tw,xxx-js,xxx-fj
#
sharding.jdbc.datasource.xxx-ha.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.xxx-ha.driver-class-name=com.mysql.cj.jdbc.Driver
sharding.jdbc.datasource.xxx-ha.jdbcUrl=jdbc:mysql://localhost:3306/xxx_ha?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
sharding.jdbc.datasource.xxx-ha.username=root
sharding.jdbc.datasource.xxx-ha.password=root
#
sharding.jdbc.datasource.xxx-sd.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.xxx-sd.driver-class-name=com.mysql.cj.jdbc.Driver
sharding.jdbc.datasource.xxx-sd.jdbcUrl=jdbc:mysql://localhost:3306/xxx_sd?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
sharding.jdbc.datasource.xxx-sd.username=root
sharding.jdbc.datasource.xxx-sd.password=root
#
sharding.jdbc.datasource.xxx-zj.type=com.zaxxer.hikari.HikariDataSource
sharding.jdbc.datasource.xxx-zj.driver-class-name=com.mysql.cj.jdbc.Driver
sharding.jdbc.datasource.xxx-zj.jdbcUrl=jdbc:mysql://localhost:3306/xxx_zj?useUnicode=true&am