Spring MVC key Interface handlermapping Handleradapter

Source: Internet
Author: User

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
    1. <init-param>   
    2.     < param-name>detectallhandlermappings</param-name>  
    3.     <param-value> False</param-value>  
    4. </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
    1. <init-param>
    2. <param-name>detectallhandleradapters</param-name>
    3. <param-value>false</param-value>
    4. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.