springboot2.0登录拦截器没能执行成功

1.webconfig实现于WebMvcConfigurer

/**
 * Web相关配置
 *
 * Created by git on 2019/5/29.
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private LicenseCheckInterceptor licenseCheckInterceptor;

    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/login");
    }

}

2.自定义拦截器LicenseCheckInterceptor

public class LicenseCheckInterceptor extends HandlerInterceptorAdapter 

3.问题:但是登录时却进入不了LicenseCheckInterceptor拦截器
4.解决:发现SwaggerConfig继承WebMvcConfigurationSupport ,导致与上面的WebMvc配置冲突了

public class SwaggerConfig extends WebMvcConfigurationSupport

便将swagger 也实现于WebMvcConfigurer ,问题解决

public class SwaggerConfig implements WebMvcConfigurer 

参考:https://www.cnblogs.com/gabriel-y/p/12266719.html

发布了14 篇原创文章 · 获赞 92 · 访问量 1571

猜你喜欢

转载自blog.csdn.net/jn19970215/article/details/104297173