What is the difference between displaying a spring request and displaying urls?

I stumbled upon this question after reading the log of my spring boot application in debug mode.

When launched while spring RequestMappingHandlerMapping is "Search for query mappings in the application context" and finds the resquest mappings defined on my controllers. Later BeanNameUrlHandlerMapping is “Searching for URL BeanNameUrlHandlerMapping in the Application Context” and cannot find it for every bean defined in my context (URL paths are not defined)

My question is, what is the difference between query display and url mapping, can anyone link the documentation to read what BeanNameUrlHandlerMapping looking for?

+2
spring spring-boot spring-mvc
source share
2 answers

RequestMappingHandlerMapping

According to the documentation, RequestMappingHandlerMapping :

Creates RequestMappingInfo instances from @RequestMapping type and method annotations at the @Controller class level.

A RequestMappingInfo can be created using the constructor:

 public RequestMappingInfo(String name, PatternsRequestCondition patterns, RequestMethodsRequestCondition methods, ParamsRequestCondition params, HeadersRequestCondition headers, ConsumesRequestCondition consumes, ProducesRequestCondition produces, RequestCondition<?> custom) 

and presents a request with a set of conditions that must be matched.

BeanNameUrlHandlerMapping

BeanNameUrlHandlerMapping :

Implementing the HandlerMapping interface that maps URLs to beans with names starting with a slash ("/"),

and like AbstractDetectingUrlHandlerMapping :

Discovery of URL mappings for the beans handler by introspecting all the defined beans in the application context.

+1
source share

RequestMappingHandlerMapping defines all the possible URLs that you can handle in the application. No need to read URLs from controller annotations. Mappings can be calculated. For example. the question provides a solution when query mappings are generated on the fly on behalf of a method.

RequestMapping should be comlex with, for example. @PathParameter when displaying the text "\user\{userId}"

So, step 1, register all the URLs that we can process.

Then for each URL we need to find a bean that needs to be called to process some URL (to find the method that spring should call).

0
source share

All Articles