最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
springboot拦截器执行两次解决方法代码
时间:2022-06-29 02:11:37 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下springboot拦截器执行两次解决方法代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
springboot拦截器执行两次
原因是:
org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error
也是一个controller路径为/error
@Configuration
public class MVCConfig extends WebMvcConfigurationSupport {
//自定义的拦截器
@Bean
public SecurityInterceptor getSecurityInterceptor() {
return new SecurityInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
//添加拦截器
InterceptorRegistration registration = registry.addInterceptor(getSecurityInterceptor());
//排除的路径
registration.excludePathPatterns("/login");
registration.excludePathPatterns("/logout");
//将这个controller放行
registration.excludePathPatterns("/error");
//拦截全部
registration.addPathPatterns("/**");
}
}
Springboot拦截器原理
根据当前请求,找到**HandlerExecutionChain**** 【可以处理请求的handler以及handler的所有 拦截器】
先来顺序执行所有拦截器的 preHandle方法
如果当前拦截器prehandler返回为true。则执行下一个拦截器的preHandle
如果当前拦截器返回为false。直接 倒序执行所有已经执行了的拦截器的 afterCompletion;
如果任何一个拦截器返回false。直接跳出不执行目标方法
所有拦截器都返回True。执行目标方法
倒序执行所有拦截器的postHandle方法。
前面的步骤有任何异常都会直接倒序触发afterCompletion
页面成功渲染完成以后,也会倒序触发 afterCompletion
相关文章
- 二重螺旋怎么拍照 拍照方法 10-30
- 二重螺旋妮弗尔夫人怎么配队 妮弗尔夫人配队攻略 10-30
- 二重螺旋煜明怎么获取 煜明获取攻略 10-30
- 新月同行伊底怎么配队-伊底阵容搭配推荐 10-30
- 逃离鸭科夫零号区爱心满满任务怎么完成 爱心满满任务流程攻略 10-30
- 三国志8重制版游玩配置需求介绍说明 10-30

