栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将CSS文件添加到Spring Boot + Spring Security Thymeleaf文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将CSS文件添加到Spring Boot + Spring Security Thymeleaf文件

您的模式

../static/css
与您的相对URL不匹配
../static/css/index.css
,请参见AntPathMatcher:

PathMatcher
Ant-style 的路径模式的实现。

此映射代码的一部分已从Apache Ant借来。

映射使用以下规则匹配URL:

  • ?
    matches one character
  • *
    matches zero or more characters
  • **
    matches zero or more directories in a path
  • {spring:[a-z]+}
    将正则表达式匹配
    [a-z]+
    为名为“ spring”的路径变量

和Spring Boot参考:

默认情况下,资源映射在上,

/**
但是您可以通过进行调整
spring.mvc.static-path-pattern

您的请求将被重定向到登录表单,因为您尚未登录并且所有其他请求都需要身份验证。

要解决此问题,请将模式更改为

/css/**
/images/**

一个更好的静态资源解决方案是WebSecurity#ignoring:

允许添加

RequestMatcher
Spring Security应该忽略的实例。Spring Security提供的Web
Security(包括
SecurityContext
)在
HttpServletRequest
该匹配项上不可用。通常,注册的请求应该仅是静态资源的请求。对于动态请求,请考虑映射请求以允许所有用户使用。

用法示例:

 webSecurityBuilder.ignoring() // ignore all URLs that start with /resources/ or /static/     .antMatchers("/resources/**", "/static/**");


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/594821.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号