错误提示如下:
Cannot resolve configuration property ‘spring.datasource.dynamic.datasource.master.driverClassName’
解决方法:
在pom.xml引入对应依赖
<!-- dynamic-datasource 多数据源-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
处理结果
项目正常启动
properties配置多数据源(dynamic)信息
# 配置动态数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# 主库数据源
spring.datasource.dynamic.datasource.master.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.dynamic.datasource.master.url=jdbc:mysql://localhost:3306/flowable_table?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
spring.datasource.dynamic.datasource.master.username=root
spring.datasource.dynamic.datasource.master.password=123456
# 从库数据源
spring.datasource.dynamic.datasource.slave.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.dynamic.datasource.slave.url=
spring.datasource.dynamic.datasource.slave.username=
spring.datasource.dynamic.datasource.slave.password=