Reputation: 540
So I had static css files loading correctly and then for whatever reason, can't tell why, they stopped loading right. Here is my project structure:
import in 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.
And the best part:
when inspecting website - styles.css
is loaded as index.html
in templates
folder.
what do?
Upvotes: 2
Views: 110
Reputation: 614
In spring security 4.x - the resources are permitAll
in spring security.
In spring security 5.x - you should manually config it.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()
}
Upvotes: 2
Reputation: 369
Please try to check below points:
1. ResourceHandler has css location
class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**")
.addResourceLocations("classpath:/static/css/");
}
...
}
2. Exclude *.css in spring-security rules
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/css/\**",
"/js/\**",
"/img/\**",
...
);
}
...
}
Upvotes: 0