Spring Boot 2程序不能加载 com.mysql.jdbc.Driver 问题

用Spring Boot Starter 向导生成了一个很简单SpringBoot程序, 用到了 MySQL, 总是下面不能加载 Mysql driver class 错误. 

Cannot load driver class: com.mysql.jdbc.Driver

 

刚开始以为是 application.properties 中相关的配置项写法不合规, 发现很正常. 检查了 MySQL jar 文件也很正常. 突然想起之前好像也碰到过同样的问题, 又想了很久, 终于想起上次是因为用了 spring-boot 2.0.5.RELEASE, 换成了 2.0.4.RELEASE 就好了. 这次 Spring Boot Starter 向导生成的是 2.0.6.RELEASE, 改回2.0.4.RELEASE 也好了.  

记录一下, 以免将来又碰到同样的问题.

 

附: application.properties 文件 

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

附 pom.xml 片段

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
复制代码
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>provided</scope>
    </dependency>    
复制代码

 

posted @   harrychinese  阅读(13073)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示