所以我正确加载了静态css文件,然后无论出于何种原因,都说不出原因,他们停止加载正确。这是我的项目结构:
在index.html中导入:
<head>
<link rel="stylesheet" th:href="@{/css/styles.css}"/>
</head>
我甚至试图在spring.resources.static-locations=classpath:/static/
设置application.properties
无济于事。
最好的部分:在检查网站时 - styles.css
在index.html
文件夹中加载为templates
。
做什么?
在春季安全4.x - 春天安全的资源是permitAll
。
在spring security 5.x中 - 你应该手动配置它。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()
}
请尝试检查以下几点: 1. ResourceHandler有css位置
class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**")
.addResourceLocations("classpath:/static/css/");
}
...
}
2.在spring-security规则中排除* .css
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/css/\**",
"/js/\**",
"/img/\**",
...
);
}
...
}