"Spring source learning" Springmvc URL and bean mapping principle and source code parsing

Source: Internet
Author: User

Basic process of "one" mapping

(1) SPRINGMVC configuration map, need to configure <mvc:annotation-driven > </mvc:annotation-driven> in XML configuration file

(2) after configuration, The configuration will be processed by Org.springframework.web.servlet.config.MvcNamespaceHandler and the class will be forwarded to Org.springframework.web.servlet.config.Annotati Ondrivenbeandefinitionparser do the parsing.

(3) When Annotationdrivenbeandefinitionparser is parsed, multiple objects are registered to the IOC container. which has this object org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

(4) The Requestmappinghandlermapping object invokes the object Afterpropertiesset () method to make a map of the URL and bean when the IOC instantiates the bean phase.

(5) The mapping is to find the bean labeled @controller, @RequestMapping annotations from the IOC, and then reflect all the methods mehod the object and the URL values configured in the annotations are mapped.

(6) The Init () method is called at Org.springframework.web.servlet.DispatcherServlet initialization, and after IOC parsing, AOP is prepared, the initstrategies ( ApplicationContext context) method called inithandlermappings (context). Injects all beans in the IOC that implement the Handlermapping interface into the Dispatcherservlet property list

"Two" <mvc:annotation-driven > </mvc:annotation-driven> configuration, The beans that are registered in the IOC by Annotationdrivenbeandefinitionparser parsing are roughly the following

"1" org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
Property:
Org.springframework.web.accept.ContentNegotiationManagerFactoryBean

"2" Org.springframework.web.bind.support.ConfigurableWebBindingInitializer
Property:
Org.springframework.format.support.FormattingConversionServiceFactoryBean
Org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean

"3" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
Property:
ContentNegotiationManager:org.springframework.web.accept.ContentNegotiationManagerFactoryBean
WebBindingInitializer:org.springframework.web.bind.support.ConfigurableWebBindingInitializer
Messageconverters: Below

"4" <mvc:message-converters register-defaults= "true" >
==>org.springframework.http.converter.bytearrayhttpmessageconverter (default load)
==>org.springframework.http.converter.stringhttpmessageconverter (default load)
==>com.alibaba.fastjson.support.spring.fastjsonhttpmessageconverter (config)

==>org.springframework.http.converter.resourcehttpmessageconverter (default load)
==>org.springframework.http.converter.xml.sourcehttpmessageconverter (default load)
==>org.springframework.http.converter.support.allencompassingformhttpmessageconverter (default load)

==> Org.springframework.http.converter.feed.AtomFeedHttpMessageConverter (not loaded)
==>org.springframework.http.converter.feed.rsschannelhttpmessageconverter (not loaded)

==>org.springframework.http.converter.xml.mappingjackson2xmlhttpmessageconverter (not loaded)
==>org.springframework.http.converter.xml.jaxb2rootelementhttpmessageconverter (default load)
==>org.springframework.http.converter.json.gsonhttpmessageconverter (not loaded)

"5" Org.springframework.web.servlet.config.CompositeUriComponentsContributorFactoryBean
Property:
HandlerAdapter:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
ConversionService:org.springframework.format.support.FormattingConversionServiceFactoryBean


"6" Org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor
"7" Org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
"8" Org.springframework.web.servlet.handler.MappedInterceptor
"9" Org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver
"10" Org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
"11" org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
"12" Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
"13" Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter

"Spring source learning" Springmvc URL and bean mapping principle and source code parsing

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.