gpt4 book ai didi

java - 使用 TOMCAT-Jersey Rest 获取 404 错误

转载 作者:搜寻专家 更新时间:2023-11-01 03:21:57 28 4
gpt4 key购买 nike

我正在使用 JERSEY2.15:-

Java 类:-

package packages.newJersey;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/rest")
public class SimpleWebService {

private static String versions = "4.1";

@GET
@Produces(MediaType.TEXT_HTML)
public String simpleMessage() {

return "<p>This is a simple REST</p>";

}

@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String version() {

return "<p>Version Number:</p> " + versions;

}
}

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>LatestJersey</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.package</param-name>
<param-value>packages.newJersey</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>

即使我将显示名称用作:- LatestJersey

默认情况下 tomcat 正在打开:- http://localhost:8080/RESTFULServiceWithLatestJersey/

当我点击:- http://localhost:8080/RESTFULServiceWithLatestJersey/hello/rest

我收到 404 错误

有人可以帮我吗?

最佳答案

一切看起来都很好,除了这个

jersey.config.server.provider.package

应该是

jersey.config.server.provider.packages  

您缺少 s

关于java - 使用 TOMCAT-Jersey Rest 获取 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28138629/

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