Getting rid of web.xml in Vaadin 7 with VaadinServlet

会有一股神秘感。 提交于 2019-12-06 11:12:49

问题


I'm new to Java and Vaadin. A basic Vaadin project is using web.xml for all the mappings. If I want to use the @WebServlet annotation I need to create an inner class which somewhere inherits from HttpServlet.

@SuppressWarnings("serial")
public class VaadinplaygroundUI extends UI {

    @WebServlet(urlPatterns="/Helo")
    public static class Servlet extends VaadinServlet {

    }

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();

I know, I'm missing some overwritten methods in the inner class Servlet to get it working, but I don't know which. There are many examples in the internet for Vaadin 6.x where the inner class extends AbstractApplicationServlet.

Thanks for any help.


回答1:


Here's for 7.x:

public class MyUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true, initParams = {
            @WebInitParam(name = "ui", value = "com.example.MyUI"),
            @WebInitParam(name = "productionMode", value = "false") })
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        ..
    }
}

And for 7.1 and newer:

public class MyUI extends UI {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = MyUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {
        ..
    }
}


来源:https://stackoverflow.com/questions/17163577/getting-rid-of-web-xml-in-vaadin-7-with-vaadinservlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!