• 周六. 10 月 12th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

The problem of static resources intercepted by interceptors in springboot 2.0

King Wang

1 月 3, 2022

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/

发表回复