jdbcUrl is required with driverClassName
springboot2.0配置多數據源:
spring.datasource.primary.url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.primary.username=root
spring.datasource.primary.password=root
spring.datasource.primary.driver-class=com.mysql.cj.jdbc.Driver
spring.datasource.secondary.url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.secondary.username=root
spring.datasource.secondary.password=root
spring.datasource.secondary.driver-class=com.mysql.cj.jdbc.Driver
改為:
spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.primary.username=root
spring.datasource.primary.password=root
spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.secondary.jdbc-url=jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.secondary.username=root
spring.datasource.secondary.password=root
spring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url 數據庫的 JDBC URL。
spring.datasource.jdbc-url 用來重寫自定義連接池
官方文檔的解釋是:
因為連接池的實際類型沒有被公開,所以在您的自定義數據源的元數據中沒有生成密鑰,而且在IDE中沒有完成(因為DataSource接口沒有暴露屬性)。另外,如果您碰巧在類路徑上有Hikari,那么這個基本設置就不起作用了,因為Hikari沒有url屬性(但是確實有一個jdbcUrl屬性)。在這種情況下,您必須重寫您的配置如下:
原文地址:https://blog.csdn.net/newbie_907486852/article/details/81391525