为什么Eclipse中的预览服务器不尊重我的@WebServlet注释? [英] Why won't the preview server in Eclipse respect my @WebServlet annotation?

查看:52
本文介绍了为什么Eclipse中的预览服务器不尊重我的@WebServlet注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 @WebServlet 批注,如下所示:

I am using the @WebServlet annotation in my app, like so:

@WebServlet("/tokenize")
public class TokenizerServlet extends HttpServlet {
   ...
}

这在Eclipse中的本地主机的J2EE预览"中不起作用.对 http://localhost:8080/myApp/tokenizer 的任何请求均返回404.从 web.xml 映射时,该URL可以正常工作.

This does not work in the "J2EE Preview at localhost" within Eclipse. Any request to http://localhost:8080/myApp/tokenizer returns a 404. When mapped from the web.xml, this same URL works fine.

但是,在将应用程序(以我的情况为例)部署到Azure时,它确实可以工作.因此问题不在代码或配置中,这与Eclipse中的预览服务器有关.

However, when the app is deployed (to Azure, in my case), it does work. So the problem isn't in the code or the config, it's something to do with the preview server in Eclipse.

我如何配置预览服务器以遵守我的注释?我到处都看过了,似乎没有什么可说的.我的 web.xml 的根元素看起来像这样:

How do I need to configure the preview server to respect my annotation? I've looked everywhere, and there doesn't seem to be much config to speak of. The root element of my web.xml looks like this:

<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">

在项目的"J2EE预览"节点下,我有这个:

Under the "J2EE Preview" node in the project, I have this:

更新-

我从未对此找到解决方案,但是我发现在本地运行Tomcat是如此容易,以至于我刚开始这样做.如果有人遇到相同的问题,我将在此留出这个问题,只是为了让您知道您并不孤单,也许有人会在某个时候提供答案.

I never got a solution to this, but I found it so easy to run Tomcat locally, that I just started doing that instead. I'm leaving this question here in case anyone else has the same problem, just so you know you're not alone, and perhaps someone will provide an answer at some point.

推荐答案

在引入Servlet 3.0时,servlet中的注释概念就浮出水面.下面的任何较低版本均不支持注释.我认为在您的IDE中,您一直在使用3.0以下的servlet版本.在创建动态Web项目时,可以更改此版本.

The concept of annnotation in servlet came into picture while introducing servlet 3.0. Any lower version below wont support annotation. I think in your IDE you have been using a servlet version below 3.0. While creating a dynamic web project it is possible to change this version.

这篇关于为什么Eclipse中的预览服务器不尊重我的@WebServlet注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆