Quick revision
The short answer
The front controller pattern means one entry point receives every request and delegates it to the right handler, so common work such as routing, conversion, error handling and locale resolution lives in one place. In Spring MVC that entry point is DispatcherServlet. Spring Boot's DispatcherServletAutoConfiguration creates it and registers it with the servlet container, mapped to / by default, and spring.mvc.servlet.path changes that mapping; the servlet then uses beans from the application context, such as handler mappings and message converters, to do its work.
What to remember
In this answer, we saw that the front controller pattern puts one entry point in front of all requests so that common work is done once and handlers stay small. In Spring MVC that entry point is DispatcherServlet, which Spring Boot's DispatcherServletAutoConfiguration creates and registers through a DispatcherServletRegistrationBean mapped to / by default. spring.mvc.servlet.path moves the mapping, unlike the context path, and the servlet delegates its work to strategy beans from the application context, such as handler mappings, adapters, exception resolvers and message converters.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The front controller pattern means one entry point receives every request and delegates it to the right handler, so common work such as routing, conversion, error handling and locale resolution lives in one place. In Spring MVC that entry point is DispatcherServlet. Spring Boot's DispatcherServletAutoConfiguration creates it and registers it with the servlet container, mapped to / by default, and spring.mvc.servlet.path changes that mapping; the servlet then uses beans from the application context, such as handler mappings and message converters, to do its work.
Why this question is asked
Every Spring MVC request passes through DispatcherServlet, yet most developers never see it, because Spring Boot sets it up silently. Interviewers ask about it because knowing the pattern and the registration explains many everyday puzzles: why all URLs share one error page, why a path prefix appears or disappears, and where customization hooks live. In this answer, we will recap servlets, explain the front controller pattern, see how Boot registers the servlet, change its mapping, and look at the beans it relies on.
1A Quick Recap of Servlets
A servlet is a Java class that a servlet container, such as Tomcat, calls to handle HTTP requests. The container keeps a table that maps URL patterns to servlets: requests for /reports/* go to one servlet, requests for /admin/* to another. In the early days, each page or feature had its own servlet, and each one repeated the same work: parse parameters, check the user, handle errors, render the page.
That repetition is what the front controller pattern removes.
2The Front Controller Pattern
With a front controller, a single servlet receives all requests. It does the common work once, then decides which piece of application code, the handler, should process the request, and calls it. Handlers become small and focused, and cross-cutting concerns, such as converting JSON, applying interceptors, resolving the locale and turning exceptions into responses, are handled consistently for every endpoint.
In Spring MVC, DispatcherServlet is that front controller, and our @Controller methods are the handlers. The reason Spring can offer so many features with so little code in our controllers is that DispatcherServlet does the shared work around them.
- Tomcat receives GET /orders/42matches the / mapping
- DispatcherServletthe single front controller
- Find the handlervia
HandlerMappingbeans - Invoke itvia a
HandlerAdapter, with argument resolution - Write the responsevia message converters or a view
- Handle errors centrally
HandlerExceptionResolverbeans
6 steps in order. Play them, or step through them one at a time.
3How Spring Boot Registers DispatcherServlet
In a plain Spring application we used to declare DispatcherServlet in web.xml or in a WebApplicationInitializer. Spring Boot does it with auto-configuration. DispatcherServletAutoConfiguration, which applies when Spring MVC is on the classpath and the application is a servlet web application, creates a DispatcherServlet bean and a DispatcherServletRegistrationBean. The registration bean tells the embedded servlet container to add the servlet with the mapping /, so it receives every request that no more specific servlet claims.
Notice the load-on-startup value. By default the servlet is initialized lazily on the first request, which is why the first call after startup is a little slower; spring.mvc.servlet.load-on-startup=1 initializes it at startup instead. If we define our own DispatcherServlet bean, Boot backs off and uses ours.
4Changing the Mapping
Sometimes we want all MVC endpoints under a prefix, for example because another servlet must own the root, or the application is deployed under /api. The property spring.mvc.servlet.path changes the servlet's mapping.
Notice the difference from server.servlet.context-path. The context path prefixes the whole web application, including every servlet and filter, while spring.mvc.servlet.path only moves DispatcherServlet. Inside the controller, mappings are relative to the servlet path, which is why the controller code does not change.
5The Beans DispatcherServlet Uses
DispatcherServlet does not hard-code how to route or convert. When it initializes, it looks up strategy beans in the application context: HandlerMapping beans to find handlers, HandlerAdapter beans to invoke them, HandlerExceptionResolver beans to turn exceptions into responses, ViewResolver beans for template views, and resolvers for locale and multipart requests. Spring Boot, through the Spring MVC configuration it applies, registers sensible defaults, such as RequestMappingHandlerMapping and RequestMappingHandlerAdapter, which in turn use HttpMessageConverter beans like the Jackson converter for JSON.
This is the reason customization in Spring MVC usually means adding a bean or implementing WebMvcConfigurer rather than touching the servlet. A new HttpMessageConverter bean, an interceptor registered in addInterceptors, or a @ControllerAdvice with @ExceptionHandler methods all plug into the strategies the front controller already calls.
6Follow-up questions
Can an application have more than one DispatcherServlet?
Yes. We can register a second DispatcherServlet with its own child application context and a different mapping, for example /legacy/*, using another DispatcherServletRegistrationBean. It is rarely needed today; a single servlet with well-organized controllers is simpler, and different behaviour per area is usually achieved with interceptors or separate filter chains.
Where do servlet filters fit in relation to DispatcherServlet?
Filters run before the servlet, in the container's filter chain. Spring Security, CORS handling and request logging filters see the request first, then DispatcherServlet gets it. That is why a request rejected by security never reaches controller code or MVC exception handlers.
Is the front controller the same in Spring WebFlux?
The idea is the same, but WebFlux uses DispatcherHandler on a reactive server instead of a servlet.
7Conclusion
In this answer, we saw that the front controller pattern puts one entry point in front of all requests so that common work is done once and handlers stay small. In Spring MVC that entry point is DispatcherServlet, which Spring Boot's DispatcherServletAutoConfiguration creates and registers through a DispatcherServletRegistrationBean mapped to / by default. spring.mvc.servlet.path moves the mapping, unlike the context path, and the servlet delegates its work to strategy beans from the application context, such as handler mappings, adapters, exception resolvers and message converters.
Open with
The front controller pattern means a single component receives every request and delegates to the appropriate handler, so shared work like routing, conversion, error handling and locale resolution happens in one place instead of being repeated in every endpoint.
Then, if they want more
In Spring MVC, DispatcherServlet is the front controller and our controller methods are the handlers. In Spring Boot I never declare it myself: DispatcherServletAutoConfiguration creates the DispatcherServlet bean and a DispatcherServletRegistrationBean, which registers it with the embedded Tomcat under the mapping slash, so it receives every request not claimed by a more specific servlet.
By default it initializes on the first request, which load-on-startup can change. If I want MVC under a prefix, I set spring.mvc.servlet.path, for example to slash api; that only moves the DispatcherServlet, unlike server.servlet.context-path, which prefixes the whole application, and controller mappings stay relative so the code does not change.
The servlet itself is mostly a coordinator: on initialization it collects strategy beans from the application context, handler mappings like RequestMappingHandlerMapping, handler adapters, exception resolvers, view resolvers, and through the adapter the HttpMessageConverters such as Jackson. That is why customizing MVC means adding beans or a WebMvcConfigurer rather than changing the servlet.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the front controller pattern and how does Spring Boot register DispatcherServlet?": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/c422cd80a1/