我在Jersey Jersey Servlet上遇到一个奇怪的问题,我在以下配置中使用Jersey 2.21,但是,当我尝试访问rest服务时,它只给我404-Not Found错误。
奇怪的是,该日志:接受根资源类:“ / ”,但是我不是在“ / ”上请求,而是在“ / rest / * ...”上请求>
web.xml
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
...search.router.action;
...search.router.job;
...search.router.provider;
com.fasterxml.jackson.jaxrs.json
</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.response.setStatusOverSendError</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.mvc.templateBasePath</param-name>
<param-value>/webapp</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.media.multipart.MultiPartFeature,org.glassfish.jersey.server.mvc.jsp.JspMvcFeature
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.forwardOn404</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
pom
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.21</version>
</dependency>
其他服务:
@Path("/query") // deprecated only for result.html
public class QueryServlet {
@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
@GET
@Consumes
@Produces(MediaType.APPLICATION_JSON)
public String query(
@DefaultValue("EN") @HeaderParam("CloudFront-Viewer-Country") String country,
@HeaderParam("X-Forwarded-For") String userIp,
@HeaderParam("User-Agent") String userAgent,
@HeaderParam("Referer") String referer,
@HeaderParam("Host") String host,
@BeanParam QueryMeta qeryMeta
) throws Exception {
String searchUrl = searchLogic(qeryMeta, userAgent, country, userIp, host, referer);
return searchUrl;
}
我尝试过的网址: http://localhost:8084/router/rest/query
我在做什么错了?