问题描述
问题发生时间(2018-12-27)
环境版本:
- SpringBoot 2.1.1
- Mybatis 1.3.2
原始配置
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
复制代码
报错信息
Registered driver with driverClassName=com.mysql.jdbc.Driver was not found,
复制代码
报错提示
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.
复制代码
解决办法
从提示中可看出,驱动名称有变,更正驱动名称即可
更正后配置
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自带提示也可看出问题,有两种驱动都存在的问题,希望后续修复
另一种解决方案,从SpringBoot2.0之后连接池使用hikari,可根据url自动识别驱动,即如下配置也可成功运行
spring:
datasource:
username: hikaricp
password: hikaricp
url: jdbc:mysql://localhost:3306/db_test?characterEncoding=utf-8&useSSL=false
复制代码