您的模式
../static/css与您的相对URL不匹配
../static/css/index.css,请参见AntPathMatcher:
PathMatcherAnt-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:
允许添加
RequestMatcherSpring Security应该忽略的实例。Spring Security提供的Web
Security(包括SecurityContext)在HttpServletRequest该匹配项上不可用。通常,注册的请求应该仅是静态资源的请求。对于动态请求,请考虑映射请求以允许所有用户使用。用法示例:
webSecurityBuilder.ignoring() // ignore all URLs that start with /resources/ or /static/ .antMatchers("/resources/**", "/static/**");



