我正在使用JERSEY2.15: -
java class: -
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错误
有人可以帮我吗?
答案 0 :(得分:1)
一切看起来都不错,除了这个
jersey.config.server.provider.package
应该是
jersey.config.server.provider.packages
您错过了s