Search code examples
javaspringservletsvaadinvaadin-spring-boot

Custom servlet in Vaadin + Spring Boot


I'm trying to reproduce a simplified version of the official Vaadin Dashboard Demo, but I'm using Spring Boot for managing dependencies.

In DashboardServlet.java file you will find this code:

public class DashboardServlet extends VaadinServlet {
    @Override
    protected final void servletInitialized() throws ServletException {
        super.servletInitialized();
        getService().addSessionInitListener(new DashboardSessionInitListener());
    }
}

The demo is using a customized servlet.

Question: how can this be achieved in Spring Boot? How can I make Spring Boot inject my custom servlet class?


Solution

  • You must create a manage bean which name is vaadinServlet, and you want to extend the SpringVaadinServlet class. This should work:

    @Component("vaadinServlet")
    public class MySpringVaadinServlet extends SpringVaadinServlet {
    
        @Override
        protected void servletInitialized() throws ServletException {
            super.servletInitialized();
        }
    }