Java Developer interview question · Most asked

Describe the request flow in a Spring MVC (Spring Boot) application.

Summary

The servlet container runs the filter chain (including Spring Security), then the DispatcherServlet finds a handler via HandlerMapping, runs HandlerInterceptor.preHandle, resolves and validates arguments (message converters, @Valid), invokes the controller, writes the return value (or renders a view after postHandle), applies exception resolvers such as @ControllerAdvice when something throws, runs afterCompletion, and the response travels back out through the filters.

Longer Answer

@Transactional and @Cacheable apply through proxies around service calls inside the controller step. Knowing the order explains why exceptions thrown in filters bypass @ControllerAdvice and why interceptors can see which handler will run but filters can't.

Key Points

  • @Transactional and @Cacheable apply through proxies around service calls inside the controller step
  • Knowing the order explains why exceptions thrown in filters bypass @ControllerAdvice and why interceptors can see which handler will run but filters can't
  • What interviewers look for

A correct ordered flow naming filters, interceptors and exception resolvers

  • Use the answer to connect the concept back to a realistic production or interview scenario for 'Describe the request flow in a Spring MVC (Spring Boot) application.'

Comparison / Tradeoffs

Aspect Notes
Core idea The servlet container runs the filter chain (including Spring Security), then the DispatcherServlet finds a handler via HandlerMapping, runs HandlerInterceptor.preHandle, resolves and validates arguments (message converters, @Valid), invokes the controller, writes the return value (or renders a view after postHandle), applies exception resolvers such as @ControllerAdvice when something throws, runs afterCompletion, and the response travels back out through the filters.
Practical tradeoff ## What interviewers look for

A correct ordered flow naming filters, interceptors and exception resolvers. |

Explanation

What interviewers look for

A correct ordered flow naming filters, interceptors and exception resolvers.

More most-asked Java Developer questions

← All Java Developer questions