Jersey 和 Google App Engine (GAE) 不适合我

Jersey and Google App Engine (GAE) not working for me

我看过一些关于这个主题的帖子,但它们并没有帮助我找到问题所在。我正在尝试让 Jersey 2.22 与 GAE SDK 1.9.25 一起使用,但我一直收到 404。

控制台显示:

Nov 05, 2015 4:02:57 PM org.glassfish.jersey.server.ServerRuntime$Responder mapException
FINE: WebApplicationException (WAE) with no entity thrown and no ExceptionMappers have been found for this WAE. Response with status 404 is directly generated from the WAE.
javax.ws.rs.NotFoundException: HTTP 404 Not Found
    at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:323)

我的 class 看起来像这样:

package com.jt.jjbackend;

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 JJServlet {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayHello(){
        return "Hello";
    }
}

这是我的 web.xml:

<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <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.jt.jjbackend</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping> 

</web-app>

我使用了 http://localhost:8888/rest/hello,我认为这是正确的,因为当我输入伪造的 link 时,控制台中出现了不同的错误。我还添加了一个正常工作的常规测试 servlet。

我做错了什么或忽略了什么?非常感谢您的帮助。

斯蒂芬

在您的 web.xml 中将 com.sun.jersey.config.property.packages 更改为 jersey.config.server.provider.packages。前者适用于泽西 1.x,而后者适用于 2.x。它们在各自的版本中表示相同的意思,但它们不能互换。