我正在创建一个基本的API来发送数独谜题,我在运行API时遇到了麻烦。这是我第一次尝试自己使用Spring,我遵循了与教程相同的步骤,但它一直崩溃。
这是日志。
2023-05-04T12:34:40.727-04:00 INFO 21276 --- [ main] com.sudoku.SudokuApplication : Starting SudokuApplication using Java 17.0.6 with PID 21276 (C:\Users\olive\Downloads\sudokuApi\demo\target\classes started by olive in C:\Users\olive\Downloads\sudokuApi\demo)
2023-05-04T12:34:40.734-04:00 INFO 21276 --- [ main] com.sudoku.SudokuApplication : No active profile set, falling back to 1 default profile: "default"
2023-05-04T12:34:42.424-04:00 INFO 21276 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-05-04T12:34:42.424-04:00 INFO 21276 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.8]
2023-05-04T12:34:42.546-04:00 INFO 21276 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-05-04T12:34:42.658-04:00 ERROR 21276 --- [ main] com.zaxxer.hikari.HikariConfig : Failed to load driver class org.postgresql.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@1d44bcfa
2023-05-04T12:34:42.666-04:00 INFO 21276 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-05-04T12:34:42.719-04:00 ERROR 21276 --- [ main] o.s.boot.SpringApplication : Application run failed
我的应用程序属性如下,我更改了用户名和密码,但我确信我有正确的。
spring.main.banner-mode=off
logging.level.org.springframework=ERROR
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/sudoku
spring.datasource.username=CHANGED
spring.datasource.password=CHANGED
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
我的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>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Sudoku</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</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>
</project>
我真的不知道如何阅读这些错误代码,所以我复制粘贴他们,并试图找到任何东西,但似乎没有工作。
我是不是漏掉了什么?
2条答案
按热度按时间wxclj1h51#
从您的日志“Failed to load driver class org.postgresql.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@1d44bcfa”
看起来你的类路径上没有驱动jar
kq4fsx7k2#
我在您的Maven pom.xml中没有看到Postgres JDBC驱动程序。我建议添加它,除非我错过了:
我回去看到你有驱动程序,但没有版本。我不知道你为什么要创建scope runtime。我会改变的确保在创建包之后在包中看到JAR。