Spring Boot + Spring MVC

What happens when a request hits a Spring Boot application?

A request enters the embedded servlet container, passes through filters, reaches DispatcherServlet, gets mapped to a controller method, calls application logic, and returns a response.

Spring BootSpring MVCBackendRequest Lifecycle

The Short Answer

A Spring Boot request is not handled directly by your controller. Your controller is only one stop in a longer request pipeline.

The request usually flows from the embedded servlet container, through filters, into Spring MVC's DispatcherServlet, then to the correct controller method, then back out as an HTTP response.

The Mental Model

Client

Embedded Tomcat

Filters

DispatcherServlet

HandlerMapping

Controller

Service Layer

JSON Response

The request flows through infrastructure layers before reaching your application code, then travels back as an HTTP response.

The Request Lifecycle, Step by Step

1

Client sends HTTP request

A browser, frontend app, Postman, mobile app, or another backend sends an HTTP request.

2

Embedded servlet container receives it

In a typical Spring Boot servlet application, embedded Tomcat receives the network request and turns it into servlet request/response objects.

3

Servlet filters run

Filters are outside Spring MVC and often handle cross-cutting concerns before the request reaches your controller. Common examples include Spring Security, JWT authentication, OAuth2 token validation, Okta/Auth0 integration, CORS handling, request logging, tracing, metrics, and request/response wrapping.

4

DispatcherServlet receives the request

DispatcherServlet is the front controller for Spring MVC. It coordinates the request instead of doing all the work itself.

5

HandlerMapping finds the controller method

Spring checks mappings like @GetMapping, @PostMapping, and @RequestMapping to find the matching controller method.

6

HandlerAdapter invokes the method

Spring adapts the HTTP request into method arguments such as @PathVariable, @RequestParam, @RequestBody, and then calls the controller method.

7

Controller calls service layer

The controller should usually stay thin. It delegates business logic to the service layer instead of containing all the application logic itself.

8

Service layer executes business logic

The service layer coordinates application behavior such as validation, transactions, orchestration, external API calls, caching, domain rules, and business workflows.

9

Repository layer accesses the database

Repositories handle persistence and data access. In many Spring Boot applications this means Spring Data JPA repositories interacting with databases through Hibernate/JPA.

10

Return value becomes HTTP response

For REST APIs, Spring often serializes the returned object into JSON or XML using HTTP message converters such as Jackson.

11

Response travels back through the chain

Interceptors and filters may run again on the way out before the client receives the response. For example, a logging filter may record the final HTTP status and response time, while an interceptor may add tracing information, audit details, or custom response headers before the response is returned to the client. Filters/interceptors are not just “before” hooks. They often wrap the request/response lifecycle like middleware pipelines.

The Interview-Friendly Explanation

In Spring Boot, the embedded servlet container receives the HTTP request first. Filters may run before the request reaches Spring MVC. Then DispatcherServlet acts as the front controller. It uses HandlerMapping to find the right controller method and HandlerAdapter to invoke it. The controller usually delegates to services, and the returned value is converted into an HTTP response.

Where Filters, Interceptors, and Controllers Fit

Filter

Runs before the request reaches DispatcherServlet. Good for servlet-level concerns like security, CORS, logging, and request wrapping.

Interceptor

Runs inside Spring MVC, around controller execution. Good for MVC-aware preHandle, postHandle, and afterCompletion logic.

Controller

Handles the application endpoint. It should translate HTTP input into application calls, not contain all business logic.

Common Beginner Mistake

Many people think the request goes directly from the browser to the controller.

Beginner Mental Model

Browser → Controller

This is easy to remember, but it hides most of what Spring MVC is doing.

Better Mental Model

Request
Filters
DispatcherServlet
Controller Method
Response

This shows the infrastructure around the controller and sounds much stronger in interviews.

That simplified view is okay at first, but in interviews you should show that you understand the hidden infrastructure around the controller.

Simple Controller Example

java
@RestController
@RequestMapping("/api/products")
public class ProductController {

    private final ProductService productService;

    // constructor injection
    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @GetMapping("/{id}")
    public ProductResponse getProduct(@PathVariable Long id) {
        return productService.getProduct(id);
    }
}

When a request hits /api/products/10, Spring maps it to this controller method, extracts 10 as the path variable, invokes the method, and serializes the returned object.

What Makes This Page Different

The useful part is not memorizing the component names. The useful part is knowing what kind of work happens at each stage.

A senior-level explanation should connect the request lifecycle to real production concerns: authentication, logging, metrics, exception handling, validation, serialization, controller design, and service-layer boundaries.

Common Interview Follow-Ups

Is DispatcherServlet created by my controller?

No. DispatcherServlet is part of Spring MVC infrastructure. It receives requests and dispatches them to controllers.

Do filters run before controllers?

Yes. Servlet filters run before the request reaches the Spring MVC controller path.

What finds the controller method?

HandlerMapping finds the matching handler based on URL, HTTP method, and mapping annotations.

What converts Java objects to JSON?

Spring uses HTTP message converters, commonly Jackson-based JSON conversion in typical REST APIs.

Where should business logic live?

Usually in the service/domain layer, not directly inside controllers.

Final Takeaway

A Spring Boot request is a pipeline. The controller is important, but it is only one stop. Strong candidates understand the whole path: container → filters → DispatcherServlet → mapping → controller → service → response conversion → response back to client.