【问题标题】:Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource: spring boot 2.4.1无法将“”下的属性绑定到 com.zaxxer.hikari.HikariDataSource:spring boot 2.4.1
【发布时间】:2021-01-01 13:24:54
【问题描述】:

我得到这个输出将运行我的 spring 应用程序

***************************
APPLICATION FAILED TO START
***************************

Description:

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

我的 pom.xml 看起来像这样:

<?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.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com</groupId>
<artifactId>couponProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>couponProject-Spring </name>
<description>coupon project part 2 spring</description>

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

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>



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

我的 application.properties 看起来像这样:

spring.datasource.url=jdbc:mysql://localhost:3306/couponproject?serverTimezone=Israel&createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=1234
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
# spring.jpa.properties.hibernate.format_sql=true
# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

我是 spring 新手,所以我真的不明白为什么我会得到这个输出 我使用了spring初始化器spring JPA 我读过类似的问题,但我不太明白解决方案

【问题讨论】:

  • 请给MySQL驱动依赖并执行

标签: java spring eclipse spring-boot java-ee-6


【解决方案1】:

您的项目无法找到 jar,因为 MYSQL Drivers 缺少 maven 依赖项。请为 mySQL 8 添加以下依赖项,以便为您的应用程序提供可用的驱动程序。将其添加到 pom.xml 的 &lt;dependencies&gt; 部分中。

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.15</version>
</dependency>

或者,如果您想要另一个 8.X 或 5.X 版本的基于 MySQL 的依赖项(基于您正在使用的 MySQL 版本),请从此处使用正确的 maven 依赖项:https://mvnrepository.com/artifact/mysql/mysql-connector-java

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2018-08-22
    • 2012-06-15
    • 2020-11-20
    • 2020-02-14
    相关资源
    最近更新 更多