gpt4 book ai didi

java - HTTP 状态 500 – 内部服务器错误 – 服务器遇到意外情况,导致无法完成请求

转载 作者:行者123 更新时间:2023-12-01 16:21:51 26 4
gpt4 key购买 nike

所以我尝试在 Eclipse 上使用 Tomcat 和 Maven 制作一个非常简单的 Web 服务。我在 pom.xml 中添加了这些依赖项:

  <dependencies>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>3.0.0-M1</version>
</dependency>

</dependencies>

我刚刚将其添加到我的默认 web.xml 中:

<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>

我只是想得到一个简单的字符串:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("car")
public class Car {

@GET
@Path("carName")
@Produces(MediaType.TEXT_PLAIN)
public String carName() {
return "Subaru";
}
}

控制台日志:

SEVERE: Servlet [jersey-servlet] in web application [/WebService01] threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1042)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4871)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5180)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
...

enter image description here

在 macCatalina 10.15.4 上运行

最佳答案

如何添加到 pom.xml jersey-container-servlet-core(其中包含缺少的容器类)?

org.glassfish.jersey.servlet.ServletContainer

https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet-core/3.0.0-M1

关于java - HTTP 状态 500 – 内部服务器错误 – 服务器遇到意外情况,导致无法完成请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62251025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com