zoukankan      html  css  js  c++  java
  • springboot2.0+ 使用拦截器导致静态资源被拦截

    在spring1.0+的版本中,配置拦截器后是不会拦截静态资源的。其配置如下:

    @Configuration
    public class WebMvcConfig extends WebMvcConfigurerAdapter {
    
        @Autowired
        private RememberAuthenticationInterceptor rememberAuthenticationInterceptor;
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(rememberAuthenticationInterceptor)
                    .excludePathPatterns("/static/**")
                    .addPathPatterns("/**");
        }
    }

    但是在使用spring2.0+时,配置拦截器之后,就会拦截静态资源访问,此时我们需要用对应版本的方式去解决,如下:

    @Configuration
    public class InterceptorConfig implements WebMvcConfigurer {
     
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
           registry.addInterceptor(new LoginInterceptor())
                                    .addPathPatterns("/**")
                                           .excludePathPatterns("/static/**");
        }
    }  
    
    此处要实现的接口是WebMvcConfigurer
  • 相关阅读:
    Python学习4
    Python学习3
    Python学习2
    表空间
    sqlplus常用设置
    HashMap和LinkedHashMap
    堆栈源码
    观察者模式
    策略模式
    java线性表
  • 原文地址:https://www.cnblogs.com/kingsonfu/p/10386601.html
Copyright © 2011-2022 走看看