Helius
2021-06-29 5252d1396e21a16774be699a5ba1c8d39c14a22e
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
43
44
45
46
47
48
49
50
package com.xzx.gc.config;
 
import com.xzx.gc.interceptor.AuthInterceptor;
import com.xzx.gc.interceptor.SessionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
/**
 * @author zan.zhong
 * @date 2018-07-08 22:33
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
 
 
        registry.addInterceptor(sessionInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html","/error");
 
        // 拦截所有请求,除去exclude的请求
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html","/error","/admin/**");
    }
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //加载静态资源
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    }
 
 
 
    @Bean
    public AuthInterceptor authenticationInterceptor() {
        return new AuthInterceptor();
    }
 
    @Bean
    public SessionInterceptor sessionInterceptor() {
        return new SessionInterceptor();
    }
 
}