本周六「上海源创会」,与一线大牛一起聊聊:PHP、Flink、k8s、微服务架构,点击立刻报名!
指数
0
Watch 2.4k Star 4.7k Fork 2.3k

ThinkGem / JeeSite 4.xJavaAGPL-3.0

jeesite4.0多数据源配置项目启动报错

已完成
crazyYxd  创建于

该问题是怎么引起的?

配置多数据源yml文件如下,总共配置了两次,因为不知道怎么配置才是正确的。所以只有各种尝试。

第一种配置方案如下:

#======================================#
#========== Database sttings ==========#
#======================================#
# 数据库连接
jdbc: 
  # 多数据源名称列表,启用方式:@MyBatisDao(dataSourceName="ds2")启用所数据源配置
  dataSourceNames: lins,lins_user,lins_account
  # Mysql 数据库配置,配置默认数据源
  lins: 
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
        init: 1
        minIdle: 3
        maxActive: 20
  
  # 多数据源配置:lins_user
  lins_user:
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins_user?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
      init: 1
      minIdle: 3
      maxActive: 20
      
  # 多数据源配置:lins_account
  lins_account:
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins_account?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
      init: 1
      minIdle: 3
      maxActive: 20  

以下是尝试第二种配置方案:

# 数据库连接
jdbc: 
  # Mysql 数据库配置,配置默认数据源
  lins: 
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
        init: 1
        minIdle: 3
        maxActive: 20
  # 多数据源名称列表,启用方式:@MyBatisDao(dataSourceName="ds2")启用所数据源配置
  dataSourceNames: lins_user,lins_account
  # 多数据源配置:lins_user
  lins_user:
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins_user?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
      init: 1
      minIdle: 3
      maxActive: 20
      
  # 多数据源配置:lins_account
  lins_account:
    type: mysql
    driver: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.3.31:3306/lins_account?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
    username: root
    password: root
    testSql: SELECT 1
    encrypt:
      username: false
      password: true
    pool:
      init: 1
      minIdle: 3
      maxActive: 20  

重现步骤

两种配置方案试过之后依然不行,哪位大神遇到过同样的问题麻烦给小弟指点下迷津。感激不尽!

报错信息

加粗部分是报错的根源


|_ | / __'()| | / |
_ | | __ __ ___ | |_ | __ / /| |
( .| |//\ )| | | | /\ / /
| |_
_|_._.|___|| _)_.(___ | :: JeeSite V4.1.3 ::
======================================|
|==========================

欢迎使用  V4.1.3

您当前的版本为社区版,官方网站:http://jeesite.com

机器码是:cb829e887097ba272b48cc107ebed314
产品名称:
公司名称:

===================================================================

03-12 16:46:16.146 [32mINFO [0;39m [36m[o.s.b.w.embedded.tomcat.TomcatWebServer][0;39m - Tomcat initialized with port(s): 8080 (http)

03-12 16:46:16.341 [33mWARN [0;39m [36m[c.j.common.datasource.RoutingDataSource][0;39m - Set default target data source is null .

03-12 16:46:18.778 [32mDEBUG[0;39m [36m[com.jeesite.common.beetl.BeetlUtils ][0;39m - Beetl config files: [classpath:/config/beetl-core.properties, classpath:/config/beetl.properties]
03-12 16:46:18.912 [32mDEBUG[0;39m [36m[c.j.c.m.m.provider.SelectSqlProvider ][0;39m - 1毫秒: SELECT a.status AS "status", a.create_by AS "createBy", a.create_date AS "createDate", a.update_by AS "updateBy", a.update_date AS "updateDate", a.remarks AS "remarks", a.module_code AS "moduleCode", a.module_name AS "moduleName", a.description AS "description", a.main_class_name AS "mainClassName", a.current_version AS "currentVersion", a.upgrade_info AS "upgradeInfo" FROM js_sys_module a WHERE a.status = #{sqlMap.where#status#EQ1} ORDER BY a.update_date DESC
03-12 16:46:18.919 [33mWARN [0;39m [36m[o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext][0;39m - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbUpgrade': Invocation of init method failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection: Cannot determine target DataSource for lookup key [null]

The error may exist in com/jeesite/modules/sys/dao/ModuleDao.java (best guess)

The error may involve com.jeesite.modules.sys.dao.ModuleDao.findList

The error occurred while executing a query

请问怎么配置多数据源,文档中没有提到。只是yml配置文件中给出示例配置。按照示例配置之后项目启动还报错。有遇到同样问题并完美解决的同学辛苦告诉一下怎么解决的。谢谢了!

6732_thinkgem 共3人参与

评论 (2)

技术群675172775 2019-03-13 17:19

这是大部分人首次都会遇到的问题,希望官方能给一个比较详细的说明

6732_thinkgem
ThinkGem 2019-03-18 22:04 拥有者

第二种方案对,需要有一个默认的数据源,dataSourceNames里只指定扩展的数据源名称。你的报错信息估计是yml文件格式读取错误,也许yml有格式错误。检查缩进,每级缩进2个空格

登录 后才可以发表评论

负责人
标签
未设置
里程碑
关联分支
开始时间
未设置
结束时间
未设置
置顶选项
优先级

搜索帮助

14_float_left_people 14_float_left_close