SpringBoot中请求响应源码解析(就是SpringMVC)
1、定位到DispatcherServlet.java的doDispatch()方法。
2、断点定位于此处。第一处断点决定handler是哪一个。第二处断点决定采用的handler适配器是哪一个。
(1)在第一处断点step into进入DispatcherServlet.java的getHandler方法,并且可以看到this.handlerMappings的size=5。
5种handlerMapping如下图:
(2)在该段代码step into查看如何匹配
进入如下代码,继续step into进入getHandlerInternal(request)
进入getHandlerInternal后继续super.getHandlerInternal(request)
进入该段代码后,继续stepinto lookupHandlerMethod();
进入lookupHandlerMethod后,将查询到的最佳匹配加入matches数组。进入查询代码addMatchingMappings()
addMatchingMappings将最佳匹配加入matches,返回到lookupHandlerMethod
返回lookupHandlerMethod
正常匹配的情况下,返回匹配到的handlerMethod
最终返回到DispatcherServlet.java中的handler变量
——————————记录第一次读源码(后续继续改进)



