handlermapping
Spring MVC uses handlermapping to find and save mapping relationships between URL requests and processing functions.
Taking defaultannotationhandlermapping as an example to see the role of handlermapping in detail
Defaultannotationhandlermapping will scan the @requestmapping annotations in all currently registered spring beans to find out the relationship between the URL and the handler method handler and associate it.
Handleradapter
Spring MVC actually invokes the handler function through Handleradapter.
Taking Annotationmethodhandleradapter as an example
After finding the corresponding handler method according to Handlermapping in Dispatcherservlet, first check all the available Handleradapter registered in the current project, Find the Handleradapter you can use based on the Supports method in Handleradapter. By calling the handle method in Handleradapter to process and prepare the parameters and annotation in the handler method (this is how spring MVC turns the parameters in Reqeust into handle method), and finally calls the actual handle method.
detectallhandlermappings
By default, spring MVC loads all beans in the current system that implement the Handlermapping interface. If you only expect spring MVC to load the specified handlermapping, you can modify the initial parameters of Dispatcherservlet in Web. XML and set the value of Detectallhandlermappings to False
XML code
- <init-param>
- < param-name>detectallhandlermappings</param-name>
- <param-value> False</param-value>
- </init-param >
Spring MVC looks for a bean named "handlermapping" and acts as the only handlermapping in the current system.
If handlermapping is not defined, spring MVC will follow the Org.springframework.web.ser defined in Dispatcherservlet.properties in the directory where Org.springframework.web.servlet.DispatcherServlet resides Vlet. Handlermapping content to load the default handlermapping (the user does not have a custom strategies case).
detectallhandleradapters
The effect is similar to detectallhandlermappings, except that the object is Handleradapter. Also through
XML code
- <init-param>
- <param-name>detectallhandleradapters</param-name>
- <param-value>false</param-value>
- </init-param>
To force the system to load only the bean name "Handleradapter" Handleradapter. If it is not loaded, the default handleradapter will be loaded according to the contents of the Org.springframework.web.servlet.HandlerAdapter defined in Dispatcherservlet.properties.
Spring MVC key Interface handlermapping Handleradapter