How is an incoming request mapped to a controller and mapped to a method?

Technology CommunityCategory: SpringHow is an incoming request mapped to a controller and mapped to a method?
VietMX Staff asked 3 years ago

Spring uses handler mappings to associate controllers with requests. Two of the commonly used handler mappings are BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping.

In BeanNameUrlHandlerMapping, when the request URL matches the name of the bean, the class in the bean definition is the controller that will handle the request.

On the other hand, in SimpleUrlHandlerMapping, the mapping is more explicit. You can specify the number of URLs and each URL can be explicitly associated with a controller.

If you are using annotations to configure Spring MVC, which you should, then @RequestMapping annotations are used to map an incoming request to a controller and a handler method.

You can also configure the @RequestMapping annotation by the URI Path, query parameters, HTTP methods of a request, and HTTP headers present in the request.