无法将“”下的属性绑定到 com.zaxxer.hikari.HikariDataSource:spring boot 2.4.1
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource: spring boot 2.4.1
我得到这个输出将 运行 我 spring app
***************************
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
我读过类似的问题,但我不太明白解决方案
您的项目无法找到 jar,因为 MYSQL Drivers 缺少 maven 依赖项。请为 mySQL 8 添加以下依赖项,以便为您的应用程序提供可用的驱动程序。将其添加到 pom.xml 的 <dependencies>
部分。
<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 .
我得到这个输出将 运行 我 spring app
***************************
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 我读过类似的问题,但我不太明白解决方案
您的项目无法找到 jar,因为 MYSQL Drivers 缺少 maven 依赖项。请为 mySQL 8 添加以下依赖项,以便为您的应用程序提供可用的驱动程序。将其添加到 pom.xml 的 <dependencies>
部分。
<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 .