zoukankan      html  css  js  c++  java
  • springboot 多数据源之错误 HikariPool-1

    数据源连接报错:

     之前在1.5.7的版本的时候用该数据源配置没问题,看如下所示

    springboot1.5.7配置多数据源:

             datasource.master.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true
             datasource.master.username=root
             datasource.master.password=123456
             datasource.master.driver-class-name=com.mysql.jdbc.Driver


            datasource.master.url=jdbc:oracle:thin:@localhost:1521:test
            datasource.master.username=acct
            datasource.master.password=123456
            datasource.master.driver-class-name=oracle.jdbc.driver.OracleDriver
            datasource.master.max-idle=10
            datasource.master.max-wait=10000
            datasource.master.min-idle=5
            datasource.master.initial-size=5
            datasource.master.validation-query=SELECT 1
            datasource.master.test-on-borrow=false
            datasource.master.test-while-idle=true
            datasource.master.time-between-eviction-runs-millis=18800

    后来在springboot2.3版本的时候集成多数据源配置时,出现如上错误:修改配置为如下所示即可解决

           

             datasource.master.jdbc-url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true
             datasource.master.username=root
             datasource.master.password=123456
             datasource.master.driver-class-name=com.mysql.jdbc.Driver


            datasource.master.jdbc-url=jdbc:oracle:thin:@localhost:1521:test
            datasource.master.username=acct
            datasource.master.password=123456
            datasource.master.driver-class-name=oracle.jdbc.driver.OracleDriver
            datasource.master.max-idle=10
            datasource.master.max-wait=10000
            datasource.master.min-idle=5
            datasource.master.initial-size=5
            datasource.master.validation-query=SELECT 1
            datasource.master.test-on-borrow=false
            datasource.master.test-while-idle=true
            datasource.master.time-between-eviction-runs-millis=18800

    spring.datasource.url 数据库的 JDBC URL。

    spring.datasource.jdbc-url 用来重写自定义连接池

    官方文档的解释是:

    因为连接池的实际类型没有被公开,所以在您的自定义数据源的元数据中没有生成密钥,而且在IDE中没有完成(因为DataSource接口没有暴露属性)。另外,如果您碰巧在类路径上有Hikari,那么这个基本设置就不起作用了,因为Hikari没有url属性(但是确实有一个jdbcUrl属性)。在这种情况下,您必须重写您的配置

     启动后查询,如图所示:

     

    可以看到第一个数据源的连接没问题了,但是第二个数据源连接没找到驱动

    修改配置:

    datasource.cluster.driver-class-name=oracle.jdbc.driver.OracleDriver

    如下:
    datasource.cluster.driver-class-name=oracle.jdbc.OracleDriver

     如此就ok了

  • 相关阅读:
    Dapper数据库字段和model属性映射
    SQLServer性能调优之缓存
    python&django 实现页面中关联查询小功能(基础篇)
    pythonのdjango select_related 和 prefetch_related()
    pythonのdjango 在控制台用log打印操作日志
    pythonのdjango Form简单应用。
    pythonのdjango 信号
    pythonのdjango 缓存
    pythonのdjango CSRF简单使用
    pythonのdjango Session体验
  • 原文地址:https://www.cnblogs.com/haoliyou/p/9604241.html
Copyright © 2011-2022 走看看