SpringBoot mysql驱动问题

问题描述

问题发生时间(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
复制代码

转载于:https://juejin.im/post/5c9f53836fb9a05e462b8d9a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值