| | |
| | | package com.moral.api.config.Interceptor; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | 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; |
| | | |
| | | import com.moral.api.interceptor.AuthenticationInterceptor; |
| | | import java.util.ArrayList; |
| | | |
| | | import com.moral.api.interceptor.WebInterceptor; |
| | | |
| | | @Configuration |
| | | public class WebAppConfiguration implements WebMvcConfigurer { |
| | | |
| | | //读取不需拦截路径 |
| | | @Bean |
| | | @ConfigurationProperties("mvc.interceptor.exclude") |
| | | public ArrayList<String> getExcludePath(){ |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(new AuthenticationInterceptor()) |
| | | .addPathPatterns("/**") |
| | | .excludePathPatterns("/**/login/**", "/**/logout/**", "/swagger-ui.html/**", "/swagger-resources/**","/**/verificationCode/**","/**/user/**"); |
| | | InterceptorRegistration regisration = registry.addInterceptor(new WebInterceptor()); |
| | | ArrayList<String> excludePath = getExcludePath(); |
| | | regisration.addPathPatterns("/**/**");//设置拦截路径 |
| | | regisration.excludePathPatterns(excludePath);//设置不拦截路径 |
| | | } |
| | | } |