【问题标题】:How do i fix the "Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource" error?如何修复“无法将''下的属性绑定到 com.zaxxer.hikari.HikariDataSource”错误?
【发布时间】:2020-11-14 22:51:22
【问题描述】:

我已经有几个月没有使用过 spring 或任何 java 了。我正在尝试创建一个与我之前所做的类似的简单 Spring 项目。 但是,当我运行应用程序时,我在项目创建一开始就收到以下错误。 这很奇怪,因为我的其他项目运行良好。任何帮助都将不胜感激。

谢谢

1 错误

   Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

   Property: driver-class-name
   Value: com.mysql.cj.jdbc.Driver
   Origin: "driverClassName" from property source "source"
   Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig 
   class 
   loader or Thread context classloader

   Action:

   Update your application's configuration

2 POM

  <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven- 
   4 
  4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
   <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.goodLife</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>demo</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>11</java.version>
  </properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>2.1.6.RELEASE</version>

    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>



    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>



    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity5</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>





    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jetbrains</groupId>
        <artifactId>annotations</artifactId>
        <version>RELEASE</version>
        <scope>compile</scope>
    </dependency>
   </dependencies>

    <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <layout>ZIP</layout>
            </configuration>
        </plugin>
    </plugins>
   </build>

 </project>

3 应用程序属性

server.port=8080

spring.jpa.hibernate.ddl-auto=update
spring.datasource.platform=mysql
spring.datasource.dataSourceClassName=com.mysql.jdbc.Driver 
spring.datasource.url=jdbc:mysql://0.0.0.0:3306/goodlife? 
useUnicode=true&characterEncoding=utf-8&autoReconnect=true
spring.datasource.username=springuser
spring.datasource.password=ThePassword

【问题讨论】:

  • 您对mysql-connector-java 的依赖应该使com.mysql.cj.jdbc.Driver 可用,但Maven 在下载其jar 文件时可能已损坏它。尝试从 Maven 的缓存中清除它并再次运行您的应用程序。

标签: java mysql spring spring-boot jdbc


【解决方案1】:

所以下面的链接解释了我的问题和解决方法:https://blog.csdn.net/qq_38261445/article/details/91899747

解释:“首先这是springboot中的一个项目,大致意思是某个驱动类com.mysql.cj.jdbc.Driver没有加载,你报这个错误是因为找不到对应的驱动连接数据库.package,所以springboot项目中唯一能涉及到的配置就是application.properties和application.yml文件;的"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 2020-01-20
    • 2022-11-27
    • 2019-09-02
    相关资源
    最近更新 更多