| 9 | import com.interceptor.AuthorizationInterceptor; |
| 10 | |
| 11 | @Configuration |
| 12 | public class InterceptorConfig extends WebMvcConfigurationSupport{ |
| 13 | |
| 14 | @Bean |
| 15 | public AuthorizationInterceptor getAuthorizationInterceptor() { |
| 16 | return new AuthorizationInterceptor(); |
| 17 | } |
| 18 | |
| 19 | @Override |
| 20 | public void addInterceptors(InterceptorRegistry registry) { |
| 21 | registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/**").excludePathPatterns("/static/**"); |
| 22 | super.addInterceptors(registry); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * springboot 2.0配置WebMvcConfigurationSupport之后,会导致默认配置被覆盖,要访问静态资源需要重写addResourceHandlers方法 |
| 27 | */ |
| 28 | @Override |
| 29 | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| 30 | registry.addResourceHandler("/**") |
| 31 | .addResourceLocations("classpath:/resources/") |
| 32 | .addResourceLocations("classpath:/static/") |
| 33 | .addResourceLocations("classpath:/admin/") |
| 34 | .addResourceLocations("classpath:/img/") |
| 35 | .addResourceLocations("classpath:/front/") |
| 36 | .addResourceLocations("classpath:/public/"); |
| 37 | super.addResourceHandlers(registry); |
| 38 | } |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected