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();
|
}
|
|
}
|