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>    

猜你喜欢

转载自www.cnblogs.com/harrychinese/p/springboot_cannot_load_jdbc_driver.html