-
Client Sends a Request
- The request first reaches the embedded server (like Tomcat, Jetty, etc.).
-
DispatcherServlet Takes Control
- Springโs
DispatcherServletis the front controller that receives all incoming HTTP requests.
- Springโs
-
Filters are Triggered
-
Any configured filters run first. These can handle:
- Authentication & Authorization
- CORS policies
- Logging, etc.
-
-
HandlerMapping Matches the Request
- Spring uses
HandlerMappingto find the correct controller method based on URL and HTTP method.
- Spring uses
-
Interceptors Run
-
Any registered interceptors execute:
preHandle()runs before the controllerpostHandle()andafterCompletion()run after
-
-
Controller Logic Executes
- The actual controller method runs and returns a response object.
-
Exception Handlers Kick In (If Needed)
- If something goes wrong, global exception handlers (
@ControllerAdvice, etc.) catch and handle the error.
- If something goes wrong, global exception handlers (
-
Filters Execute Again (on the Way Out)
- Response flows back through the filter chain again before leaving the server.
-
Response Sent to the Client
- Finally, the response is serialized (e.g., to JSON) and sent back to the client.
I once had a bug where an interceptor failed because it was trying to access authentication info before the filter had processed it.
๐ Fixed it by adjusting the filter order and adding detailed logging to each phase of the request flow โ which helped trace exactly where things broke.