| package com.moral.api.config.mvc; | 
|   | 
| import com.moral.api.interceptor.ManageInterceptor; | 
| import org.springframework.beans.factory.annotation.Value; | 
| 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.ResourceHandlerRegistry; | 
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | 
|   | 
| import java.util.ArrayList; | 
|   | 
| @Configuration | 
| public class SpringMVCconfig implements WebMvcConfigurer{ | 
|   | 
|     /** | 
|     * @Description: 获取yaml中配置的不拦截路径 | 
|             * @Param: [] | 
|             * @return: java.util.ArrayList<java.lang.String> | 
|             * @Author: 陈凯裕 | 
|             * @Date: 2021/3/9 | 
|             */ | 
|     @Bean | 
|     @ConfigurationProperties("mvc.interceptor.exclude") | 
|     public ArrayList<String> getExcludePath(){ | 
|         return new ArrayList<>(); | 
|     } | 
|   | 
|     @Override | 
|     public void addInterceptors(InterceptorRegistry registry) { | 
|         InterceptorRegistration regisration = registry.addInterceptor(new ManageInterceptor()); | 
|         ArrayList<String> excludePath = getExcludePath(); | 
|         regisration.addPathPatterns("/**/**");//设置拦截路径 | 
|         regisration.excludePathPatterns(excludePath);//设置不拦截路径 | 
|     } | 
|   | 
|     @Override | 
|     public void addResourceHandlers(ResourceHandlerRegistry registry) { | 
|         registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); | 
|         registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); | 
|         registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); | 
|         WebMvcConfigurer.super.addResourceHandlers(registry); | 
|     } | 
| } |