You have learned that DispatcherServlet
is the thing that dispatches the request to the handler methods based on the request mapping, but in order to interpret the mappings defined in a request mapping, DispatcherServlet
needs a HandlerMapping
(org.springframework.web.servlet.HandlerMapping
) implementation. DispatcherServlet
consults with one or more HandlerMapping
implementations to know which handler can handle the request. So HandlerMapping
determines which Controller to call.
HandlerMapping
interface provides the abstraction for mapping requests to handlers. The HandlerMapping
implementations are able to inspect the request and come up with an appropriate Controller. Spring MVC provides many HandlerMapping
implementations, and the one we are using to detect and interpret mappings from the @RequestMapping
annotation is the RequestMappingHandlerMapping
(org.springframework.web.servlet.mvc.method.annotation. RequestMappingHandlerMapping
) class. To start using RequestMappingHandlerMapping
, we have to add the @EnableWebMvc
annotation in our web application context configuration file, so that Spring MVC can create and register a bean for RequestMappingHandlerMapping
in our web application context. If you remember, we already configured the @EnableWebMvc
annotation in
Chapter 2, Spring MVC Architecture – Architecting Your Web Store under the Understanding web application context configuration section.