SpringMVC源码解析-HandlerExecutionChain
发布日期:2021-06-30 12:25:42 浏览次数:2 分类:技术文章

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

最终会调用HandlerInterceptor的

preHandle

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

applyPostHandle

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

triggerAfterCompletion

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

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所提供的方法。

转载地址:https://javaedge.blog.csdn.net/article/details/106565459 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SpringMVC源码解析从service到doDispatch
下一篇:Java反射包下的Method类中的Invoke方法

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月08日 00时18分21秒