Custom servlet in Vaadin + Spring Boot

2.8k Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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();
    }
}