在整合shiro时验证登录时,发现加载不了静态资源,刚开始以为是thymeleaf的问题,搜索增加以下配置,
spring.resources.static-locations=classpath:/static/
spring.mvc.static-path-pattern=/static/**
或者:
在pom.xml中添加标签,指定静态资源
仍然加载不上资源,寻找好久后,考虑到项目中配置过拦截器,觉得可能是过滤器的问题,于是改变方向。
在拦截器配置类中发现继承了WebMvcConfigurationSupport,搜索资料知道继承这个类会覆盖默认静态资源路径:
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
@Autowired
private MyInterceptor myInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(myInterceptor)
//设置拦截路径
.addPathPatterns("/**")
//设置忽略路径
.excludePathPatterns("/login","/js/**","/css/**","/images/**");
super.addInterceptors(registry);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 一定要是/**
registry.addResourceHandler("/**")
//加载静态目录
.addResourceLocations("classpath:/static/");
super.addResourceHandlers(registry);
}
}
设置完之后解决问题