前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringMVC源码解析-HandlerExecutionChain

SpringMVC源码解析-HandlerExecutionChain

作者头像
JavaEdge
发布2021-02-22 14:56:14
3420
发布2021-02-22 14:56:14
举报
文章被收录于专栏:JavaEdgeJavaEdge

最终会调用HandlerInterceptor的

preHandle

调用所有的HandlerInterceptor拦截器并调用其preHandler方法。

applyPostHandle

获取所有的拦截器并调用其postHandle方法。

triggerAfterCompletion

触发afterCompletion执回调的映射HandlerInterceptors。 只会调用afterCompletion执行对于其preHandle调用已成功完成并返回true的拦截器

代码语言:javascript
复制
	void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, Exception ex)
			throws Exception {

		HandlerInterceptor[] interceptors = getInterceptors();
		if (!ObjectUtils.isEmpty(interceptors)) {
			for (int i = this.interceptorIndex; i >= 0; i--) {
				HandlerInterceptor interceptor = interceptors[i];
				try {
					interceptor.afterCompletion(request, response, this.handler, ex);
				}
				catch (Throwable ex2) {
					logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
				}
			}
		}
	}

HandlerInterceptor拦截器的最终调用实现是在DispatcherServlet的doDispatch方法中 因此,SpringMVC提供了HandlerExecutionChain来帮助我们执行所有配置的HandlerInterceptor拦截器,并分别调用HandlerInterceptor所提供的方法。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-06-05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • preHandle
  • applyPostHandle
  • triggerAfterCompletion
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档