替换Vaadin中的web.xml

时间:2014-07-29 09:07:54

标签: servlets vaadin web.xml

我使用Vaadin 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?

1 个答案:

答案 0 :(得分:0)

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

如果要使用@WebServlet annoations,则应使用Servlet 3.0版配置项目。

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

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

vaadin一书中有关如何配置web.xml的说明(请参阅第4.8.4章)

https://vaadin.com/book/-/page/application.environment.html