英文:
How do i fix the "Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource" error?
问题
1 错误
无法将属性绑定到 com.zaxxer.hikari.HikariDataSource 下:
属性: driver-class-name
值: com.mysql.cj.jdbc.Driver
来源: "driverClassName" 来自属性源 "source"
原因: 无法在 HikariConfig 类加载器或线程上下文类加载器中加载驱动程序类 com.mysql.cj.jdbc.Driver
操作:
更新您的应用程序配置
2 POM
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
英文:
I haven't used spring or any java in a few months now. And I am trying to create a simple Spring project similar to a previous one I did.
However, I am getting the following error at the very start of the project creation, when I run the application.
Its strange because my other project runs fine. Any help at all is appreciated.
Thanks
1 Error
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 Application Properties
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
答案1
得分: 0
以下是翻译好的内容:
所以下面的链接解释了我的问题和解决方案:https://blog.csdn.net/qq_38261445/article/details/91899747
解释:“首先,这是一个在springboot中的项目。大致意思是某个驱动程序类com.mysql.cj.jdbc.Driver未被加载。您报告此错误是因为找不到连接到数据库的相应驱动程序包,因此在springboot项目中可能涉及的唯一配置是application.properties和application.yml文件;of”。
英文:
So the following link explains my issue and the resolution : https://blog.csdn.net/qq_38261445/article/details/91899747
Explanation : "First of all, this is a project in springboot. It roughly means that a certain driver class com.mysql.cj.jdbc.Driver is not loaded. You are reporting this error because you cannot find the corresponding driver to connect to the database. Package, so the only configuration that can be involved in the springboot project is application.properties and application.yml files; of"
专注分享java语言的经验与见解,让所有开发者获益!
评论