Spring Web Request Lifecycle — describes the sequence of steps an HTTP request goes through in a Spring (Boot) application from arrival to response.
🧩 Lifecycle Steps
- Client sends HTTP request
Browser, mobile app, or client sends request to the server. - Servlet Container (Tomcat/Jetty)
The request hits the Servlet container, which delegates it toDispatcherServlet. DispatcherServlet- Central Spring MVC component.
- Receives all incoming requests (
front controller). - Dispatches to appropriate controllers via HandlerMapping.
- Handler Mapping
Determines which controller method (@RequestMapping) will handle the request. - Handler Adapter
Invokes the controller method and prepares the return value. - Controller (
@Controller/@RestController)
Processes business logic and returns ModelAndView or object. - View Resolver (for @Controller)
If using templates (Thymeleaf, JSP), resolves which view to render.
If@RestController, object is converted to JSON via HttpMessageConverter. - Interceptors & Filters
Filter→ runs before DispatcherServlet.HandlerInterceptor→ preHandle, postHandle, afterCompletion around controller execution.ExceptionHandler→ handles errors.
- Response to Client
Response is serialized (JSON/HTML) and sent back via the Servlet container.
🧠 Key Points
- Filters → Servlet container level (pre/post request).
- Interceptors → Spring MVC level (controller execution).
DispatcherServlet→ heart of Spring Web.- HttpMessageConverters → transform objects to JSON/XML automatically.
