- 问题背景
- 解决方案
- Lyric: 前进 找寻新的记忆和空气
使用mybatis的时候报主数据源找不到错误:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource ### The error may exist in com/lanran/transactional/dao/PaymentMapper.java (best guess) ### The error may involve com.lanran.transactional.dao.PaymentMapper.insertBatchSomeColumn ### The error occurred while executing an update ### Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource解决方案
1 因为添加了mybatisplus的多源配置依赖,但是配置文件没有写是多源的相关配置,所以报错
com.baomidou dynamic-datasource-spring-boot-starter 3.5.0
- 第一种方式,如果不使用多源配置,就把这个依赖删除掉
- 第二种方式,application设置多源配置
server:
port: 40001
spring:
datasource:
druid:
stat-view-servlet:
enabled: true
dynamic:
# 配置全局druid参数,请按需配置
druid:
initial-size: 5
max-active: 8
min-idle: 3
max-wait: 1000
validation-query: 'select 1'
datasource:
master:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
slave_1:
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test2?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
作为程序员第 212 篇文章,每次写一句歌词记录一下,看看人生有几首歌的时间,wahahaha …



