我可以使用嵌入式Grizzly容器通过main方法启动我的应用程序,我所有的Jersey资源都会按照我的预期进行响应。但是,当我在webapps目录($CATALINA_HOME/webapps/ROOT.war
)中放弃我的战争时,我得到404s。可能导致这种情况的原因是什么?
我的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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>example</display-name>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
编辑:在/ hello中公开了一个资源。我尝试将<url-pattern>
更改为/hello
,/rest/*
,rest/*
,只更改*
,并尝试各种卷曲语句,如:
$ curl -i http://localhost:8080/rest/hello
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Length: 0
Date: Tue, 21 Mar 2017 06:07:10 GMT
Hello资源:
package com.example.hello;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("hello")
public class HelloWorldResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayhello() {
return "hello";
}
}