0422Loading class `com.mysql.jdbc.Driver‘. This is deprecated

文章描述了在运行Java项目时遇到的初始化Spring嵌入式WebApplicationContext的错误,原因在于旧版的MySQL驱动(com.mysql.jdbc.Driver)已过时,需更新为com.mysql.cj.jdbc.Driver。作者指导读者检查POM文件并找到配置文件中的driver-class-name部分进行修正。
摘要由CSDN通过智能技术生成

运行java文件时,报
信息: Initializing Spring embedded WebApplicationContext

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.

项目pom文件里,引入

 <!-- mysql驱动 -->

        <dependency>

            <groupId>com.mysql</groupId>

            <artifactId>mysql-connector-j</artifactId>

            <version>8.2.0</version>

        </dependency>

检查所有的pom依赖,也未有相应的版本出现。所以对各模块的配置文件进行检查,果然是yml文件配置有异常:
spring:

  datasource:                                           # 数据源的相关配置

    type: com.zaxxer.hikari.HikariDataSource          # 数据源类型:HikariCP

    driver-class-name: com.mysql.jdbc.Driver          # mysql驱动

    url: jdbc:mysql://localhost:3306/foodie-shop-dev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true

    username: root

    password: xxxxx

    hikari:

      connection-timeout: 30000       # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒

      minimum-idle: 5                 # 最小连接数

      maximum-pool-size: 20           # 最大连接数

      auto-commit: true               # 自动提交

      idle-timeout: 600000            # 连接超时的最大时长(毫秒),超时则被释放(retired),默认:10分钟

      pool-name: DateSourceHikariCP     # 连接池名字

      max-lifetime: 1800000           # 连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms

      connection-test-query: SELECT 1

根据报错提示:The new driver class is `com.mysql.cj.jdbc.Driver'.

修改为:

driver-class-name:  com.mysql.cj.jdbc.Driver注意“:”后要有空格

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值