Spring / Spring7 basics Interview questions
What is the DispatcherServlet in Spring MVC?
DispatcherServlet is the single front controller that every incoming HTTP request in a Spring MVC application passes through first. It doesn't contain business logic itself; instead it coordinates the whole request-handling pipeline - consulting handler mappings, invoking interceptors, calling your controller method, and choosing how to render the result.
flowchart LR
A[HTTP Request] --> B[DispatcherServlet]
B --> C[HandlerMapping]
C --> D[Controller method]
D --> E[ViewResolver or Message Converter]
E --> F[HTTP Response]
In a Spring Boot app, DispatcherServlet is registered and configured automatically by auto-configuration, mapped to / by default. For a @RestController, it skips view resolution entirely and hands the return value straight to an HttpMessageConverter to be written as JSON or another format.
More Related questions...