【笔记】springboot-security放行静态资源
刚搞完oauth2认证 开始尝试自己搞个认证界面 然后发现有部分静态资源就是无法加载 按以下步骤检查
- 检查自己写的WebSecurityConfigurerAdapter
检查方法 public void configure(WebSecurity web) 该方法与形参HttpSecurity http的区别是前者不走过滤链
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/js/**", "/img/**");
}
- 检查静态资源有没有放对位置 thymeleaf默认会在classpath:/static/,classpath:/template/下搜索目标文件
- 以上步骤都没问题 但问题依然存在 开日志 在application.yml加入如下内容
logging:
level:
org.springframework: debug
再次运行 日志会打印一堆东西 直接搜索你缺少的文件名称 我缺少的是bootstrap的css和js文件 部分日志如下
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-3] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/css/login.css'; against '/css/**'
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/css/bootstrap/bootstrap.css'; against '/css/**'
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-2] o.s.security.web.FilterChainProxy : /css/bootstrap/bootstrap.css has an empty filter list
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-3] o.s.security.web.FilterChainProxy : /css/login.css has an empty filter list
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-2] o.s.web.servlet.DispatcherServlet : GET "/css/bootstrap/bootstrap.css", parameters={}
2023-06-19 02:18:31.624 DEBUG 574542 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet : GET "/css/login.css", parameters={}
2023-06-19 02:18:31.627 DEBUG 574542 --- [nio-8086-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2023-06-19 02:18:31.627 DEBUG 574542 --- [nio-8086-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2023-06-19 02:18:31.628 DEBUG 574542 --- [nio-8086-exec-2] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2023-06-19 02:18:31.628 DEBUG 574542 --- [nio-8086-exec-2] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
2023-06-19 02:18:31.630 DEBUG 574542 --- [nio-8086-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/error'; against '/css/**'
2023-06-19 02:18:31.630 DEBUG 574542 --- [nio-8086-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/error'; against '/js/**'
2023-06-19 02:18:31.630 DEBUG 574542 --- [nio-8086-exec-2] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/error'; against '/img/**'
根据日志可以看到是404 没找到该资源文件 但我明明放进去了啊 遂检查IDE的输出文件
太艹了 他怎么没编译到输出里去 然后mvn clean再mvn compile 看到文件有了 再运行 正常了 不知道这是IDE的bug还是啥
来自1942年冬季攻势中的中央集团军的037号17吨救援拖车
分类:
java
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术