SpringBoot mysql驱动问题

问题描述

问题发生时间(2018-12-27)mysql

环境版本:spring

  • SpringBoot 2.1.1
  • Mybatis 1.3.2

原始配置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

mybatis1.jpg

另外一种解决方案,从SpringBoot2.0以后链接池使用hikari,可根据url自动识别驱动,即以下配置也可成功运行cdn

spring:
 datasource:
 username: hikaricp
 password: hikaricp
 url: jdbc:mysql://localhost:3306/db_test?characterEncoding=utf-8&useSSL=false
复制代码
相关文章
相关标签/搜索