trace定位DispatcherServlet

我们先试下跟踪​​Servlet​​:

trace javax.servlet.Servlet *

从trace的结果可以看出来,请求最终是被​​DispatcherServlet#doDispatch()​​​处理了,但是没有办法知道是哪个​​Controller​​处理。

`---[27.453122ms] org.springframework.web.servlet.DispatcherServlet:doDispatch()
+---[0.005822ms] org.springframework.web.context.request.async.WebAsyncUtils:getAsyncManager() #929
+---[0.107365ms] org.springframework.web.servlet.DispatcherServlet:checkMultipart() #936
| `---[0.062451ms] org.springframework.web.servlet.DispatcherServlet:checkMultipart()
| `---[0.016924ms] org.springframework.web.multipart.MultipartResolver:isMultipart() #1093
+---[2.103935ms] org.springframework.web.servlet.DispatcherServlet:getHandler() #940
| `---[2.036042ms] org.springframework.web.servlet.DispatcherServlet:getHandler()

watch定位handler

trace结果里把调用的行号打印出来了,我们可以直接在IDE里查看代码(也可以用jad命令反编译)

watch org.springframework.web.servlet.DispatcherServlet getHandler returnObj

ts=2020-09-27 20:07:01; [cost=11.719144ms] result=@HandlerExecutionChain[     logger=@Slf4jLocationAwareLog[org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog@63eeba5b],     handler=@HandlerMethod[com.kq.ctrl.SalePeriodController#list(DtoProductPlanListSearch)],     interceptors=null,     interceptorList=@ArrayList[isEmpty=false;size=2],     interceptorIndex=@Integer[-1], ]

 可以看到处理请求的handler是 com.kq.ctrl.SalePeriodController.list