springboot2.0版本后配置拦截器会导致静态资源被拦截

转载:https://blog.csdn.net/wangfuxu14/article/details/80670648

springboot2.0版本后配置拦截器会导致静态资源被拦截

解决办法:

分两步:

第一步:定义一个类实现

实现WebMvcConfigurer的类中拦截器中添加放行资源处添加静态资源文件路径:
 
  1. @Override

  2. public void addInterceptors(InterceptorRegistry registry) {

  3. registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")

  4. .excludePathPatterns("/index.html","/","/user/login","/static/**");

  5. }

第二步:配置静态文件路径

 
  1. @Override

    扫描二维码关注公众号,回复: 5976091 查看本文章
  2. public void addResourceHandlers(ResourceHandlerRegistry registry) {

  3. registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

  4. WebMvcConfigurer.super.addResourceHandlers(registry);

  5. }

静态资源文件存放在resources文件夹下的static文件夹中

猜你喜欢

转载自blog.csdn.net/ww_ndsc_ww/article/details/81128816
今日推荐