博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC 处理器执行链 (HandlerMapping)的执行过程
阅读量:5806 次
发布时间:2019-06-18

本文共 3098 字,大约阅读时间需要 10 分钟。

第一步:在web.xml中找到DispatcherServlet,然后ctrl+鼠标左键进入这个类中

第二步:ctrl+f找一个叫doDispatch的方法

//入参进来一个requestprotected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {        HttpServletRequest processedRequest = request;       处理器执行链        HandlerExecutionChain mappedHandler = null;       多部分请求 解析器  (文件上传)        boolean multipartRequestParsed = false;        WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);        try {            try {           模型(数据)和视图                ModelAndView err = null;        异常                Exception dispatchException = null;                try {           //指的是 DispatcherServlet 的实例  看看请求是不是多部分请求            
表单有文件域 上传文件了 processedRequest = this.checkMultipart(request); multipartRequestParsed = processedRequest != request;                          mappedHandler = this.getHandler(processedRequest);

第三步:ctrl+鼠标左键进入getHandler方法中

protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {        handlerMappings单列集合 。Set   List          Iterator var2 = this.handlerMappings.iterator();        HandlerExecutionChain handler;            if(!var2.hasNext())    return null;           每next()拿到一个HandlerMapping实例            HandlerMapping hm = (HandlerMapping)var2.next();            handler = hm.getHandler(request);           return handler;    }

第四步:接着ctrl+鼠标左键找getHandler方法,我们找到的是一个接口,然后ctrl+h找接口的实现类 AbstractHandlerMapping(抽象类)

public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {        Object handler = this.getHandlerInternal(request);        if(handler == null) {            handler = this.getDefaultHandler();        }        if(handler == null) {            return null;        } else {            if(handler instanceof String) {                String handlerName = (String)handler;  //  /hello                handler = this.getApplicationContext().getBean(handlerName);            }            return this.getHandlerExecutionChain(handler, request);        }    }

第五步:找getHandlerExecutionChain方法

protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {        HandlerExecutionChain chain = handler instanceof HandlerExecutionChain?(HandlerExecutionChain)handler:new HandlerExecutionChain(handler);        String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);        Iterator var5 = this.adaptedInterceptors.iterator();        while(var5.hasNext()) {            HandlerInterceptor interceptor = (HandlerInterceptor)var5.next();            if(interceptor instanceof MappedInterceptor) {                MappedInterceptor mappedInterceptor = (MappedInterceptor)interceptor;                if(mappedInterceptor.matches(lookupPath, this.pathMatcher)) {                    chain.addInterceptor(mappedInterceptor.getInterceptor());                }            } else {                chain.addInterceptor(interceptor);            }        }        return chain;    }

 

转载于:https://www.cnblogs.com/my-123/p/8617391.html

你可能感兴趣的文章
Spring ’14 Wave Update: Installing Dynamics CRM on Tablets for Windows 8.1
查看>>
MySQL 备份与恢复
查看>>
TEST
查看>>
PAT A1037
查看>>
ReactiveSwift源码解析(三) Signal代码的基本实现
查看>>
(六)Oracle学习笔记—— 约束
查看>>
[Oracle]如何在Oracle中设置Event
查看>>
top.location.href和localtion.href有什么不同
查看>>
02-创建hibernate工程
查看>>
Scrum之 Sprint计划会议
查看>>
svn命令在linux下的使用
查看>>
Gradle之module间依赖版本同步
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务(十五)Springboot整合RabbitMQ...
查看>>
SpringCloud使用Prometheus监控(基于Eureka)
查看>>
10g手动创建数据库
查看>>
Spring MVC EL表达式不能显示
查看>>
Windwos Server 2008 R2 DHCP服务
查看>>
SAS和SATA硬盘的区别
查看>>
C# 矩阵作业
查看>>
关于数据库查询时报“query block has incorrect number of result columns”
查看>>