This article explores how Spring leverages Servlet technology to bootstrap and efficiently dispatch requests in a Spring MVC application.
Spring MVC revolves around a single servlet, the DispatcherServlet, which handles every incoming request.
Spring creates and initializes an instance of WebApplicationContext, a sub-interface of ApplicationContext, when a DispatcherServlet is registered.
Spring uses a ContextLoaderListener to create and initialize a root WebApplicationContext, establishing a hierarchy where the root context provides shared beans to all DispatcherServlet instances.
Programmers can implement the WebApplicationInitializer interface to perform tasks during the application startup, allowing developers to have a say over the initialization process.
DispatcherServlet delegates the real work of processing requests to essential beans such as HandlerMapping, HandlerAdapter, and ViewResolver.
For each incoming request, the DispatcherServlet calls the service() method and then takes charge, using HandlerMappings to identify the handler and invoking it through a HandlerAdapter.
Spring Boot simplifies setting up and running a Spring MVC application by removing much of the boilerplate configuration associated with traditional setups.
With Spring Boot, setting up a Spring MVC application no longer requires extensive configuration.
Mastering the underlying architecture and design principles of Spring MVC is essential for deepening understanding about the Spring framework.