带有注释的Servlet映射无法通过Google App Engine Dev Server解析

wan*_*if2 0 google-app-engine

我试图使用注释将servlet映射到url,而不是在web.xml中进行servlet映射,如下所示:

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "GuestbookServlet", urlPatterns = "/guestbook")
public class GuestbookServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world");
    }
}
Run Code Online (Sandbox Code Playgroud)

我还在web.xml中声明了servlet的3.0规范:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0"
    metadata-complete="false">

</web-app>
Run Code Online (Sandbox Code Playgroud)

但是,当我在本地环境中运行它时,返回的响应是404.

但是,如果我只是在web.xml中映射servlet,它就可以工作.我究竟做错了什么?GAE仍然不支持3.0规格吗?

小智 5

GAE/J不支持Servlet 3.0规范

它仍然在路线图上:https://developers.google.com/appengine/docs/features#roadmap_features

您可以解决此问题,以帮助显示您对此功能的支持:https://code.google.com/p/googleappengine/issues/detail?id = 3091

这张票已经开了一个lonnnggg时间了.