Springboot配置Druid时碰到的几类问题

一、背景信息

MySQL驱动版本:5.1.49

Springboot项目application.yml中关于数据源的配置如下:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/spring_boot?useUnicode=true&characterEncoding=utf-8&useSSL=true
    username: root
    password: 12345
    driver-class-name: com.mysql.jdbc.Driver

二、几类问题

2.1  errorCode 0, state 08S01

这个错发生在【创建数据库连接】这个阶段,一般是配置文件中写错了,比如由下面这个报错信息可以看出,url 属性的值中“localhost” 被写成了 “locahost”。那自然是连接不上数据库了...

ERROR 20324:... create connection SQLException, 
url: jdbc:mysql://locahost:3306/spring_boot?useSSL=true, errorCode 0, state 08S01

2.2 Loading class `com.mysql.jdbc.Driver'. This is deprecated.

完整提示信息如下:

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.

看到这个提示说明项目中使用的MySQL驱动版本较高,原来的配置方式已不再适用,需要将原来配置文件中 driver-class-name 的值改成 “com.mysql.cj.jdbc.Driver”,如下所示:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/spring_boot?useUnicode=true&characterEncoding=utf-8&useSSL=true
    username: root
    password: 12345
    driver-class-name: com.mysql.cj.jdbc.Driver

或者可以选择版本更低的MySQL驱动版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值