問題發生時間(2018-12-27)mysql
環境版本:spring
原始配置sql
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: hikaricp
password: hikaricp
url: jdbc:mysql://localhost:3306/db_test?characterEncoding=utf-8&useSSL=false
複製代碼
報錯信息bash
Registered driver with driverClassName=com.mysql.jdbc.Driver was not found,
複製代碼
報錯提示mybatis
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
複製代碼
從提示中可看出,驅動名稱有變,更正驅動名稱便可url
更正後配置spa
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: hikaricp
password: hikaricp
url: jdbc:mysql://localhost:3306/db_test?characterEncoding=utf-8&useSSL=false
複製代碼
同時若使用IDEA自帶提示也可看出問題,有兩種驅動都存在的問題,但願後續修復code
另外一種解決方案,從SpringBoot2.0以後鏈接池使用hikari,可根據url自動識別驅動,即以下配置也可成功運行cdn
spring:
datasource:
username: hikaricp
password: hikaricp
url: jdbc:mysql://localhost:3306/db_test?characterEncoding=utf-8&useSSL=false
複製代碼