1. 程式人生 > 程式設計 >springboot2.0.0配置多資料來源出現jdbcUrl is required with driverClassName的錯誤

springboot2.0.0配置多資料來源出現jdbcUrl is required with driverClassName的錯誤

在Spring Boot 2.0配置多資料來源和Spring Boot 1.5.x之前,一些配置及用法多少有些不同,其中一個問題就是“jdbcUrl is required with driverClassName.”的錯誤

解決辦法:

在配置檔案中使用spring.datasource.jdbc-url,而不是通常使用的spring.datasource.url

spring:
 datasource:
  master:
   jdbc-url: jdbc:postgresql://192.168.1.2:5432/test?useUnicode=true&characterEncoding=utf8
   username: postgres
   password: postgres
   driverClassName: org.postgresql.Driver
   maxActive: 10
   maxIdle: 3
  worker:
   jdbc-url: jdbc:postgresql://192.168.1.3:5432/test?useUnicode=true&characterEncoding=utf8
   username: postgres
   password: postgres
   driverClassName: org.postgresql.Driver
   maxActive: 10
   maxIdle: 3

第二種方法:

在資料來源配置時使用DataSourceProperties方法。

springboot2.0.0配置多資料來源出現jdbcUrl is required with driverClassName的錯誤

到此這篇關於springboot2.0.0配置多資料來源出現jdbcUrl is required with driverClassName的錯誤的文章就介紹到這了,更多相關springboot多資料來源錯誤內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!