依赖
<dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>3.5.2</version> </dependency>
配置文件:
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource dynamic: primary: default strict: false datasource: default: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://10.100.10.70:3306/minex-pms?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: mingxin@2021 video: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://10.100.10.128:3316/ivehicle?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 username: ivehicle password: ivehicle
与单数据源不同的是在实现类增加了注解
错误使用方式(直接在其他业务中使用lambdaQuery ):
解决方式 在多数据源中编写方法然后在其他业务逻辑中调用:
标签:jdbc,mybatisPlus,true,数据源,datasource,mysql,lambdaQuery,com From: https://www.cnblogs.com/guanxiaohe/p/18189238