Skip to main content
PreparationZone Logo
PrepZone

Spring MVC Request Lifecycle

DispatcherServlet, handler mapping, and where validation and security plug in.

Pass checkpoint below

Why this matters

  • Tracing a request from Tomcat to your controller explains where filters, security, and validation run.
  • Misplaced logic in filters vs interceptors vs controllers is a common code-review failure mode.
  • Senior interviews ask you to draw the DispatcherServlet pipeline without looking at slides.

DispatcherServlet role

L1 · Fresher

One front controller maps URLs to @RequestMapping methods, invokes interceptors, and resolves return values to HTTP responses.

HandlerMapping chain

L2 · Intermediate

RequestMappingHandlerMapping picks the best matching controller method for path, method, and content type.

Argument resolvers

L3 · Advanced

@RequestBody, @PathVariable, and @RequestHeader are resolved before your method runs — failures become 400 via MethodArgumentNotValidException.

Async MVC return types

L4 · Expert

Callable, DeferredResult, and CompletableFuture release servlet threads; with virtual threads on Java 21, many teams skip async MVC for I/O-bound work.

HTTP request
DispatcherServlet
Controller method
ResponseEntity / ProblemDetail
One front controller delegates to mapped handlers, view resolvers, and exception handlers.

Hook

A client calls GET /api/books/42 with an expired JWT. BookStore must map the URL to BookController.getBook, run security filters, validate nothing on a GET, invoke the service, and return JSON — or a 401 before the controller runs. That path is the Spring MVC request lifecycle.

DispatcherServlet as front controller

Every HTTP request hits a single DispatcherServlet. It consults HandlerMapping beans to find a controller method, runs registered HandlerInterceptors, invokes the handler through HandlerAdapter, then uses HandlerExceptionResolver and ViewResolver (or message converters for REST) to build the response.

For BookStore, Boot auto-configures RequestMappingHandlerMapping and RequestMappingHandlerAdapter for annotated controllers.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 8 sections

  • Mapping to BookController
  • Argument resolution and validation
  • Interceptors and filters
  • Response rendering
  • BookStore in action
  • Runnable BookStore lab
  • Failure modes in production
  • Virtual threads on Java 21

Test yourself

Answer these before moving on — recall is what makes it stick.