Spring Boot拦截器排除项失效的问题( /error )
文章目录
问题描述
如以下代码,将/user/register与/user/login列入排除项后,在进行访问时,依旧提示重定向次数过多
/**
* @author 1iin
*/
@Configuration
public class MyWebMvcConfigurerAdapter implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
UserInterceptor userInterceptor = new UserInterceptor();
InterceptorRegistration loginRegistry = registry.addInterceptor(userInterceptor);
// 拦截路径
loginRegistry.addPathPatterns("/**");
// 排除路径
loginRegistry.excludePathPatterns("/user/register");
loginRegistry.excludePathPatterns("/user/login");
}
}解决方案
经查明后发现当请求对应路径时方法不对应时,请求路径会自动转为/error,就是因为这个原因导致了请求路径无限次的重定向

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论