泽西岛和谷歌应用引擎(GAE)不适合我

时间:2015-11-06 00:20:32

标签: java google-app-engine 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$2.run(ServerRuntime.java:323)

我的班级看起来像这样:

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我认为是正确的,因为当我进入虚假链接时,控制台中出现了不同的错误。我还添加了一个常规测试servlet,它运行得很好。

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

斯蒂芬

1 个答案:

答案 0 :(得分:1)

在您的web.xml中将com.sun.jersey.config.property.packages更改为jersey.config.server.provider.packages。前者是泽西岛1.x,而后者是2.x.它们在各自版本中的含义相同,但它们不可互换。