gpt4 book ai didi

java - JAX-RS : Tomcat runs normally but root not found (404)

转载 作者:行者123 更新时间:2023-11-28 22:53:45 25 4
gpt4 key购买 nike

我刚刚为我的 RESTful Web API 启动了 JAX-RS( Jersey )。 Tomcat运行正常但找不到root(错误404)。

错误控制台如下:

SEVERE: Servlet [Jersey REST Service] in web application [/com.G8.ws] threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5253)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5543)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

我的简单代码如下,因为我的包名是com.G8.ws,所以我做了http://localhost:8080/com.G8.ws

package com.G8.ws;


import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@Path("/v1/status")
public class V1_status {

@GET
@Produces(MediaType.TEXT_HTML)
public String returnTitle(){
return "<p>RESTful Web API using JAX/RS</p>";
}

}

下面是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>com.G8.ws</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>


<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<!-- <param-name>com.sun.jersey.config.property.packages</param-name>-->
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.G8.ws</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>

</web-app>

而且,我已经下载了jersey-archive-1.19中的所有jar文件。 。

有什么问题吗?

最佳答案

您需要 2.x 捆绑或更改声明为 1.x versionServletContainer .

<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

如果您更改为 1.x 版本,那么您将改为使用注释掉的包扫描属性

<param-name>com.sun.jersey.config.property.packages</param-name>

关于java - JAX-RS : Tomcat runs normally but root not found (404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32941615/

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