03 | import org.springframework.context.annotation.Bean; |
04 | import org.springframework.context.annotation.Configuration; |
05 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
06 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
07 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; |
09 | import com.interceptor.AuthorizationInterceptor; |
12 | public class InterceptorConfig extends WebMvcConfigurationSupport{ |
15 | public AuthorizationInterceptor getAuthorizationInterceptor() { |
16 | return new AuthorizationInterceptor(); |
20 | public void addInterceptors(InterceptorRegistry registry) { |
21 | registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns( "/**" ).excludePathPatterns( "/static/**" ); |
22 | super .addInterceptors(registry); |
26 | * springboot 2.0 配置WebMvcConfigurationSupport之后,会导致默认配置被覆盖,要访问静态资源需要重写addResourceHandlers方法 |
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); |