springboot2.0 If we use the previous way to configure interceptors , You will find that static resources are blocked .
First, in the springboot2.0 in WebMvcConfigurerAdapter Class is deprecated , If you want to use the previous functions , It needs to be implemented WebMvcConfigurer Interface , And rewrite addInterceptors() The method is to
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
// Add interceptor
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/static/**");
}
}
The above is springboot2.0 The interceptor registration method of , among LoginHandlerInterceptor It’s my custom interceptor , The above path means except “/static/**” All paths outside the path will be blocked , This solves the problem that static resources are intercepted by interceptors and the page has no style
Personal blog address :https://alexaccele.github.io/