zoukankan      html  css  js  c++  java
  • 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>    
  • 相关阅读:
    inner join 与 left join 之间的区别
    pdo Call to a member function setFetchMode() on boolean in
    PHP用星号隐藏用户名中间部分
    phpstorm里面无法配置deployment问题
    替换字符串中间部分为*
    tp3.2中between的用法
    PHP中的$this用法
    PhpStorm中实现代码自动换行
    ORM常用操作介绍
    django的admin的基础配置和使用
  • 原文地址:https://www.cnblogs.com/harrychinese/p/springboot_cannot_load_jdbc_driver.html
Copyright © 2011-2022 走看看