I'm facing a problem similar to this one, except I'm getting 400 error:
Failed to load resource: the server responded with a status of 404 (Not Found)
I'm compiling the application as an executable. I placed css file under:
resources\static\css
and in my home.html under resources\templates I'm referencing it as:
<link rel="stylesheet" type="text/css" media="all" th:href="@{/css/my.css}" />
I also tried placing it under:
resources\public\css
Also under various locations within the folder structure, with various href values, but for any location/href I get a 400 error. What am I missing?
UPDATE:
Added WebMmvConfig.java:
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}
and changed link to:
<link rel="stylesheet" type="text/css" media="all" th:href="@{/static/css/cc.css}" />
I'm still getting the same error...
UPDATE 2
I disabled web security completely in the application and sprinkled css files all over to see where it would read it from. It turns out that it does read the css file from webapp\css folder, not resources*... so this works, with web security disabled:
<link rel="stylesheet" type="text/css" media="all" th:href="@{css/cc.css}" href="css/cc.css"/>
But when I enable security it fails with 400 error. This is my config file (in a nutshell):
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/", "/login**", "/logout**", "/signup").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/my_account", true)
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService);
}
}
So, I guess the question is, why is it loading from webapp instead of resources?