天天看点

spring boot 拦截器使用

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;

    @Value("${intercept.url}")
    String interceptURL;

    /**
     * 注册自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //排除登录请求
        String []urls = interceptURL.split(",");
        List<String> urlList =new ArrayList<>(Arrays.asList(urls));
        registry.addInterceptor(loginInterceptor).excludePathPatterns(urlList);
    }
}