在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

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2021-10-24
猜你喜欢
  • 2021-06-03
  • 2021-04-08
  • 2021-09-16
  • 2022-01-12
  • 2022-02-22
  • 2021-09-12
  • 2021-05-31
相关资源
相似解决方案