我正在使用Java RESTful Web服务开展我的第一个项目,但是我遇到了一些问题。当我使用Tomcat运行服务器并输入GET服务的URL时,我收到一个HTTP状态500 - 内部服务器错误。我已经进行了数小时的研究,但找不到任何问题所在。也许pom.xml文件中存在某些问题。
以下是一些代码:
ResourceConfig:
package nl.hu.bep.IPASS.Config;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
@ApplicationPath("/restservices")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig(){
packages("nl.hu.bep.IPASS.webservices");
}
}
资源代码:
import nl.hu.bep.IPASS.model.Product;
import nl.hu.bep.IPASS.model.ProductBeheer;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
@Path("/producten")
public class ProductResource {
@GET
@Produces("application/json")
public Response getProducten(){
ProductBeheer beheer = ProductBeheer.getInstance();
return Response.ok(beheer.getAlleProducten()).build();
}
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.hu.bep.IPASS</groupId>
<artifactId>SD_IPASS_2021</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>SD_IPASS_2021</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.20</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
错误:
有人可以帮助我吗,请?
java.lang.IllegalArgumentException: Unsupported class file major version 59
。你正在运行的JVM不支持您尝试加载的类文件。具体来说,“59”是Java 15:https://javaalmanac.io/bytecode/versions/。因此,要么1)找到旧的.jar文件,要么2)运行更新的JVM。 - paulsm4