当静态资源被登录拦截器拦截时,可以进行如下配置
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/login/**")
//3、允许访问localhost:8080/static/**,使得这个路径不会被拦截器拦截
.excludePathPatterns("/static/**");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//1、添加资源处理器路径 即每次访问静态资源都得添加"/static/",例如localhost:8080/static/j1.jpg
//若registry.addResourceHandler("/s/**") 则必须访问localhost:8080/s/j1.jpg
registry.addResourceHandler("/static/**")
//2、添加了资源处理器路径后对应的映射资源路径
.addResourceLocations("classpath:/static/");
}
}
j1.jpg资源目录
当浏览器访问 j1.jpg时,访问成功