|  |  | 
 |  |  | package com.moral.api.config.Interceptor; | 
 |  |  |  | 
 |  |  | import org.springframework.boot.context.properties.ConfigurationProperties; | 
 |  |  | import org.springframework.boot.system.ApplicationHome; | 
 |  |  | 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 org.springframework.web.servlet.config.annotation.*; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  |  | 
 |  |  | 
 |  |  |     //读取不需拦截路径 | 
 |  |  |     @Bean | 
 |  |  |     @ConfigurationProperties("mvc.interceptor.exclude") | 
 |  |  |     public ArrayList<String> getExcludePath(){ | 
 |  |  |     public ArrayList<String> getExcludePath() { | 
 |  |  |         return new ArrayList<>(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         regisration.addPathPatterns("/**/**");//设置拦截路径 | 
 |  |  |         regisration.excludePathPatterns(excludePath);//设置不拦截路径 | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 添加静态资源文件,外部可以直接访问地址 | 
 |  |  |      * | 
 |  |  |      * @param registry | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     public void addResourceHandlers(ResourceHandlerRegistry registry) { | 
 |  |  |         try { | 
 |  |  |             ApplicationHome h = new ApplicationHome(getClass()); | 
 |  |  |             //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 | 
 |  |  |             String path = h.getSource().getParentFile().toString() + "/static/"; | 
 |  |  |             registry.addResourceHandler("/static/**").addResourceLocations("file:" + path); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | } |