[英]Thymeleaf incorrectly loads static files
So I had static css files loading correctly and then for whatever reason, can't tell why, they stopped loading right.所以我正确加载了静态 css 文件,然后无论出于何种原因,不知道为什么,他们停止正确加载。 Here is my project structure:这是我的项目结构:
import in index.html:在 index.html 中导入:
<head>
<link rel="stylesheet" th:href="@{/css/styles.css}"/>
</head>
I even tried to set spring.resources.static-locations=classpath:/static/
in application.properties
to no avail.我什至试图在application.properties
设置spring.resources.static-locations=classpath:/static/
无济于事。
And the best part:最好的部分: when inspecting website - styles.css
is loaded as index.html
in templates
folder.检查网站时styles.css
在templates
文件夹中作为index.html
加载。
what do?做什么?
In spring security 4.x - the resources are permitAll
in spring security.在 spring security 4.x 中 - spring security 中的资源是permitAll
。
In spring security 5.x - you should manually config it.在 spring security 5.x 中 - 您应该手动配置它。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()
}
Please try to check below points:请尝试检查以下几点:
1. ResourceHandler has css location 1.ResourceHandler有css位置
class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**")
.addResourceLocations("classpath:/static/css/");
}
...
}
2. Exclude *.css in spring-security rules 2.在spring-security规则中排除*.css
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/css/\**",
"/js/\**",
"/img/\**",
...
);
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.