Spring-mvc-MappingRegistry
MappingRegistry
- 
Author: HuiFer 
- 
源码阅读仓库: SourceHot-spring 
- 
源码路径: org.springframework.jms.annotation.EnableJms
- 
类全路径 
- 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry
- 
基本属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37class MappingRegistry { /** * key:mapping * value: mapping registration */ private final Map<T, MappingRegistration<T>> registry = new HashMap<>(); /** * key: mapping * value: handlerMethod */ private final Map<T, HandlerMethod> mappingLookup = new LinkedHashMap<>(); /** * key: url * value: list mapping */ private final MultiValueMap<String, T> urlLookup = new LinkedMultiValueMap<>(); /** * key: name * value: handler method */ private final Map<String, List<HandlerMethod>> nameLookup = new ConcurrentHashMap<>(); /** * key:handler method * value: 跨域配置 */ private final Map<HandlerMethod, CorsConfiguration> corsLookup = new ConcurrentHashMap<>(); /** * 读写锁 */ private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); }
- 
写一个简单的 controller 来进行解析 
|  |  | 
- 
前置链路追踪 - org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#registerHandlerMethod
 1 2 3 4protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) { super.registerHandlerMethod(handler, method, mapping); this.updateConsumesCondition(mapping, method); }- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#registerHandlerMethod
 1 2 3protected void registerHandlerMethod(Object handler, Method method, T mapping) { this.mappingRegistry.register(mapping, handler, method); }- 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#register本文重点的方法 
 
先将对象截图出来方便后续理解
         
   
    
createHandlerMethod
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#createHandlerMethod
|  |  | 
- 
HandlerMethod 构造函数 1 2 3public HandlerMethod(String beanName, BeanFactory beanFactory, Method method){} public HandlerMethod(Object bean, Method method) {}
HandlerMethod
- 成员变量
|  |  | 
validateMethodMapping
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#validateMethodMapping
HandlerMethod 进行验证
|  |  | 
getDirectUrls
- 
找到 mapping 匹配的 url 
- 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#getDirectUrls
|  |  | 
handlerMethod 和 name 绑定
|  |  | 
- org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMethodMappingNamingStrategy#getName
|  |  | 
initCorsConfiguration
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#initCorsConfiguration
|  |  | 
unregister
- 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#unregister移除 mapping 信息 
- 
执行 map , list 相关的移除方法. 
|  |  | 
- 原文作者:知识铺
- 原文链接:https://index.zshipu.com/geek/post/code/docs/Spring/mvc/Spring-mvc-MappingRegistry/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。
- 免责声明:本页面内容均来源于站内编辑发布,部分信息来源互联网,并不意味着本站赞同其观点或者证实其内容的真实性,如涉及版权等问题,请立即联系客服进行更改或删除,保证您的合法权益。转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。也可以邮件至 sblig@126.com
 
                
             
                
            