Junior — Middle
Where in Spring MVC does the search for controllers for handling incoming requests occur?
sobes.tech AI
Answer from AI
In Spring MVC, the search for controllers to handle incoming HTTP requests occurs in the DispatcherServlet. This is the central component that, upon initialization, scans the application context for beans annotated with @Controller or @RestController.
The DispatcherServlet uses HandlerMapping (for example, RequestMappingHandlerMapping) to match the request URL with the corresponding controller method annotated with @RequestMapping or its derivatives (@GetMapping, @PostMapping, etc.).
Thus, it is the DispatcherServlet and its related components that are responsible for discovering and routing requests to the appropriate controllers.