Spring MVC, like many other web frameworks, is designed using a "single sign-on (front controller)" design pattern, where a central Servlet, DispatcherServlet, provides common algorithm for processing requests, and the actual work is done by custom delegate components. This model is flexible and supports a variety of workflows.

DispatcherServlet, like any other Servlet, must be declared and rendered according to the Servlet specification using Java configuration or in web.xml . In turn, DispatcherServlet uses the Spring configuration to discover the delegate beans it needs to render requests, recognize views, handle exceptions, etc.

The following Java configuration example registers and initializes a DispatcherServlet that is automatically discovered by the servlet container:

public class MyWebApplicationInitializer implements WebApplicationInitializer {
    public void onStartup(ServletContext servletContext) {
        // Load the Spring web application configuration
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        // Create and register DispatcherServlet
        DispatcherServlet servlet = new DispatcherServlet(context);
        ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);
class MyWebApplicationInitializer : WebApplicationInitializer {
    override fun onStartup(servletContext: ServletContext) {
        // Load the Spring web application configuration
        val context = AnnotationConfigWebApplicationContext()
        // Create and register DispatcherServlet
        val servlet = DispatcherServlet(context)
        val registration = servletContext.addServlet("app", servlet)
In addition to using the ServletContext API directly, you can also extend AbstractAnnotationConfigDispatcherServletInitializer and override the specified methods.
For programmatic use cases, AnnotationConfigWebApplicationContext can be used as an alternative to GenericWebApplicationContext.

The following configuration example web.xml registers and initializes the DispatcherServlet:

Spring Boot follows a different initialization sequence. Instead of binding to the servlet container's lifecycle, Spring Boot uses the Spring configuration to bootstrap and bootstrap the embedded servlet container. The Filter and Servlet declarations are found in the Spring configuration and registered in the servlet container.