Servlets 替换Vaadin中的web.xml

Servlets 替换Vaadin中的web.xml,servlets,vaadin,web.xml,Servlets,Vaadin,Web.xml,我用瓦丁7。我想更改应用程序中的默认Servlet。我所做的是: public class MyVaadinApplication extends UI { @WebServlet(urlPatterns = "/*", asyncSupported = true) @VaadinServletConfiguration(productionMode = true, ui = MyVaadinApplication.class) public static class Servle

我用瓦丁7。我想更改应用程序中的默认
Servlet
。我所做的是:

public class MyVaadinApplication extends UI {

  @WebServlet(urlPatterns = "/*", asyncSupported = true)
  @VaadinServletConfiguration(productionMode = true, ui = MyVaadinApplication.class)
  public static class Servlet extends VaadinServlet {

   @Override
    public void init(ServletConfig servletConfig) throws ServletException {

      super.init(servletConfig);

      /*
       * Vaadin SessionListener
       */
       getService().addSessionInitListener(new VaadinSessionListener.VaadinSessionInitListener());
       getService().addSessionDestroyListener(new VaadinSessionListener.VaadinSessionDestroyListener());
     }
    }
  ....
它不考虑新的servlet。我试图删除Web.xml,但出现错误。
如何替换web.xml中的Servlet?

您应该首先确定项目使用的Servlet版本

如果您想使用@WebServlet注释,您应该使用Servlet版本3.0配置您的项目

在Eclipse中的Project->Properties->Project Facets->Dynamic Web Module->3.0下

否则,您必须将“Servlet”类添加到web.xml中

vaadin的书中描述了如何配置web.xml(参见第4.8.4章)


我已经将属性设置为动态Web模块->3.0。我有一个配置良好的web.xml。但是我不知道如何使用web.xml,我想在我的UI中设置Servlet。您是否检查Servlet.init()方法中的代码是否正在执行?不,它没有执行,似乎我的UI忽略了
Servlet
内部类。如果您使用maven,则Servlet代码应该在项目创建时在UI中生成。如果手动插入,可能会出错。如果可以,请将UI类的整个代码粘贴到某个位置。我可以看看。你的web.xml里有什么。如果我记得正确的话,如果您在web.xml和注释中定义了相同的选项,那么web.xml将优先考虑。查看web.xml中是否有servlet,并尝试删除该部分。