栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis报错CannotFindDataSourceException: dynamic-datasource can not find primary datasource解决方案

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis报错CannotFindDataSourceException: dynamic-datasource can not find primary datasource解决方案

Mybatis报错CannotFindDataSourceException: dynamic-datasource can not find primary datasource解决方案
  • 问题背景
  • 解决方案
  • 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 …

Lyric: 前进 找寻新的记忆和空气
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1024761.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号