无法将“”下的属性绑定到com.zaxxer.hikari.hikaridatasource:spring boot 2.4.1

vltsax25  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(395)

我得到这个输出将运行我的 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,我读过类似的问题,但我不太明白解决方案

ncecgwcz

ncecgwcz1#

您的项目无法找到jar,因为mysql驱动程序缺少maven依赖项。请为mysql 8添加以下依赖项,以便为您的应用程序提供可用的驱动程序。将其添加到 <dependencies> pom.xml的部分。

<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 .

相关问题