liulin
2024-11-24 b7a7fe6d139893108fe431cd670a74351755c223
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.lunhan.xxx.host.api;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
public class MvcTokenInterceptors implements WebMvcConfigurer {
    @Autowired
    private TokenFilter tokenFilter;
 
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加处理拦截器,拦截所有请求
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(tokenFilter);
        //配置拦截策略 所有路径都被拦截
        interceptorRegistration.addPathPatterns("/**");
        //排除配置 这里接口的跳过不使用此方式排除,通过注解“NonLogin”跳过拦截
        interceptorRegistration.excludePathPatterns(
                "/**/*.html",
                "/**/*.vue"
                , "/**/*.css"
                , "/**/*.js"
                , "/**/*.js.map"
                , "/*.ico"
                , "/**/*.jpg"
                , "/**/*.png"
                , "/**/*.woff"
                , "/**/*.ttf"
                ,"/**/*.json"
                , "/doc/*"
                , "/swagger/*"
                , "/swagger\\-ui/*"
                , "/swagger3/*"
//                , "/login/*"
//                , "/user/login"
        );
    }
}