Quick revision
The short answer
The embedded server, Tomcat by default, accepts the connection, parses the HTTP request and hands it to a worker thread. That thread runs the servlet filter chain, including Spring Security, and then DispatcherServlet, which finds the handler, runs interceptors, resolves the method arguments and invokes the controller. The return value is written by a message converter or rendered by a view; an exception is resolved by a HandlerExceptionResolver such as a @ControllerAdvice handler or, if unhandled, forwarded to /error.
What to remember
In this answer, we followed a request from Tomcat's connector to a worker thread, through the servlet filter chain where Spring Security authenticates and may reject it, into DispatcherServlet, which finds the handler, runs interceptors, resolves arguments and invokes the controller. The return value is written by a message converter or rendered by a view, and the call returns back through the filters. Exceptions are resolved by HandlerExceptionResolvers, including @ControllerAdvice, or else forwarded to /error and BasicErrorController.
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 embedded server, Tomcat by default, accepts the connection, parses the HTTP request and hands it to a worker thread. That thread runs the servlet filter chain, including Spring Security, and then DispatcherServlet, which finds the handler, runs interceptors, resolves the method arguments and invokes the controller. The return value is written by a message converter or rendered by a view; an exception is resolved by a HandlerExceptionResolver such as a @ControllerAdvice handler or, if unhandled, forwarded to /error.
Why this question is asked
Knowing the full path of a request is what turns debugging from guessing into looking. A missing header, a filter that runs twice, a 403 that never reaches our exception handler, or threads exhausted under load: each one happens at a specific stage. Interviewers ask this as a foundation question because the rest of Spring MVC hangs off it. In this answer, we will follow one request, POST /api/orders, from the socket to the response, stage by stage, and note at each stage what it does and which problems belong to it.
1From the Socket to a Worker Thread
Spring Boot starts an embedded servlet container inside the application; Tomcat is the default, and Jetty is an alternative. Tomcat listens on a port, 8080 by default. When a client connects, Tomcat's connector accepts the TCP connection, and with the default non-blocking connector a small number of threads watch many connections for incoming data.
When a full request has arrived, Tomcat takes a worker thread from its pool, 200 threads at most by default (server.tomcat.threads.max), parses the request line and headers into an HttpServletRequest, and creates an HttpServletResponse. From now on, this one thread carries the request through the whole application, unless the request goes async. If all worker threads are busy, new requests wait in a queue, which is why slow downstream calls can make a service look frozen. With spring.threads.virtual.enabled=true on Java 21 or later, Tomcat runs each request on a virtual thread instead, which makes blocking much cheaper.
2The Servlet Filter Chain
Before any Spring MVC code runs, the request passes through the servlet filters in order. Spring Boot registers several automatically: one that sets the character encoding, one that parses form bodies for PUT and PATCH, one for server observations and metrics, and Spring Security's DelegatingFilterProxy. Our own filters, such as a correlation id filter, slot in by their order values.
Spring Security is itself a chain of filters. It reads the session or the bearer token, authenticates the user, stores the result in the SecurityContext, and checks the URL rules. If the request is not allowed, Security writes a 401 or 403 response here, and DispatcherServlet never sees the request. This is why a security rejection is not handled by our @ControllerAdvice.
3DispatcherServlet Finds and Runs the Handler
At the end of the filter chain sits DispatcherServlet, the single servlet that Spring MVC uses as a front controller. It asks its handler mappings, in order, which handler serves POST /api/orders. RequestMappingHandlerMapping matches the path and method against the @PostMapping annotations it collected at startup and returns a HandlerMethod, a reference to OrderController.create, along with the interceptors that apply.
DispatcherServlet then finds a handler adapter that can run this kind of handler, RequestMappingHandlerAdapter for annotated methods, and calls each interceptor's preHandle. If any returns false, processing stops. Otherwise the adapter resolves each method argument: @RequestBody goes through a message converter that reads the JSON, @PathVariable comes from the matched path, and @Valid triggers validation. Then it invokes our method.
9 messages in order. Play them, or step through them one at a time.
4Writing the Response
What happens to the return value depends on the kind of controller. For a @RestController, a return value handler takes the ResponseEntity, sets the status and headers, chooses a media type from the Accept header and picks a message converter, Jackson for JSON, which writes the body. The response is usually committed at this point, so headers can no longer change.
For a classic @Controller returning a view name, the adapter returns a ModelAndView, the interceptors' postHandle runs, and DispatcherServlet asks a ViewResolver to find the template and render it into HTML. Either way, afterCompletion runs on every interceptor at the end, and the call returns back up through the filters in reverse order, so code after chain.doFilter() in each filter runs now. Finally Tomcat finishes the response and, with HTTP keep-alive, keeps the connection open for the next request.
5When Something Throws
If the controller, an argument resolver or an interceptor throws, DispatcherServlet catches the exception and asks its HandlerExceptionResolvers in order. ExceptionHandlerExceptionResolver looks for a matching @ExceptionHandler method in the controller or in a @ControllerAdvice. ResponseStatusExceptionResolver handles exceptions annotated with @ResponseStatus and ResponseStatusException. DefaultHandlerExceptionResolver maps Spring's own exceptions, for example a type mismatch becomes 400 and an unsupported media type 415.
If no resolver handles it, the exception leaves DispatcherServlet, passes back through the filters and reaches Tomcat. Tomcat then performs an error dispatch to /error, a second trip through the filter chain and DispatcherServlet, where Spring Boot's BasicErrorController produces the default JSON error or the whitelabel page. Exceptions thrown in filters skip DispatcherServlet's resolvers entirely and go straight to this path.
- Exception inside DispatcherServletcontroller, resolver or interceptor
- @ExceptionHandler or @ControllerAdvice matches?Yesits response is writtenNonext resolver
- @ResponseStatus or a known Spring exception?Yesmapped to a status such as 400 or 415Noexception leaves DispatcherServlet
- Container error dispatch to /error
BasicErrorControllerwrites the default error
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Does each request always run on one thread?
In the default synchronous model, yes: one worker thread carries it from the filter chain to the response. When a controller returns Callable, DeferredResult or CompletableFuture, the request goes async: the first thread is released, the result is produced elsewhere, and a second dispatch on another container thread writes the response.
Where would you look if every request takes 2 seconds before the controller logs anything?
Before DispatcherServlet: a slow filter, an authentication step calling a remote identity provider, a full worker thread pool making requests queue, or the body being read slowly from the client. Timing each filter and checking Tomcat's busy thread metric narrows it down quickly.
How do static files fit into this path?
They pass through the same filters and DispatcherServlet, but the handler is a resource handler from SimpleUrlHandlerMapping, which Boot registers for locations such as classpath:/static/. That handler streams the file, sets caching headers and returns, with no controller involved.
7Conclusion
In this answer, we followed a request from Tomcat's connector to a worker thread, through the servlet filter chain where Spring Security authenticates and may reject it, into DispatcherServlet, which finds the handler, runs interceptors, resolves arguments and invokes the controller. The return value is written by a message converter or rendered by a view, and the call returns back through the filters. Exceptions are resolved by HandlerExceptionResolvers, including @ControllerAdvice, or else forwarded to /error and BasicErrorController.
Open with
It starts in the embedded server, Tomcat by default. The connector accepts the connection, and once the request has arrived, a worker thread from Tomcat's pool, 200 max by default, parses it into an HttpServletRequest and carries it through the application.
Then, if they want more
With virtual threads enabled on Java 21, that's a virtual thread instead. First the servlet filter chain runs: Boot's encoding and observation filters, our own filters like a correlation id, and Spring Security's DelegatingFilterProxy, which authenticates the user and checks URL rules. If Security rejects the request, it writes the 401 or 403 there, and Spring MVC never sees it.
At the end of the chain is DispatcherServlet. It asks the handler mappings who serves the path, usually RequestMappingHandlerMapping returning a HandlerMethod, picks the RequestMappingHandlerAdapter, runs the interceptors' preHandle, resolves arguments, for example reading the JSON body with Jackson and validating it, and invokes the controller.
For a REST controller, the return value is written by a message converter, which usually commits the response. For a view controller, postHandle runs and then a ViewResolver renders the template. afterCompletion runs, the call unwinds back through the filters, and Tomcat completes the response and keeps the connection alive.
If something throws inside DispatcherServlet, the HandlerExceptionResolvers handle it, including @ControllerAdvice; if nothing does, Tomcat forwards to /error and Boot's BasicErrorController writes the default error.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- 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 "Describe the full life of an HTTP request in a Spring Boot MVC application, from the...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/dd000c7532/
Spring Boot backend interviews, question 7 of 16 Back to the path
More in Spring MVC architecture