【笔记】springboot-security放行静态资源

刚搞完oauth2认证 开始尝试自己搞个认证界面 然后发现有部分静态资源就是无法加载 按以下步骤检查

  1. 检查自己写的WebSecurityConfigurerAdapter
    检查方法 public void configure(WebSecurity web) 该方法与形参HttpSecurity http的区别是前者不走过滤链
@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/css/**", "/js/**", "/img/**");
}
  1. 检查静态资源有没有放对位置 thymeleaf默认会在classpath:/static/,classpath:/template/下搜索目标文件
  2. 以上步骤都没问题 但问题依然存在 开日志 在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还是啥

posted on   绝对密位  阅读(1007)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示