title: Spring Boot fails to load css file with 400 error
body: <p>I'm facing a problem similar to this one, except I'm getting 400 error:</p>
  
  <p><a href="https://stackoverflow.com/questions/22317206/failed-to-load-resource-the-server-responded-with-a-status-of-404-not-found">Failed to load resource: the server responded with a status of 404 (Not Found)</a></p>
  
  <p>I'm compiling the application as an executable. I placed css file under:</p>
  
  <pre><code>resources\static\css
  </code></pre>
  
  <p>and in my home.html under resources\templates I'm referencing it as:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" media="all" th:href="@{/css/my.css}" /&gt;
  </code></pre>
  
  <p>I also tried placing it under:</p>
  
  <pre><code>resources\public\css
  </code></pre>
  
  <p>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?</p>
  
  <p>UPDATE:</p>
  
  <p>Added WebMmvConfig.java:</p>
  
  <pre><code>@EnableWebMvc
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/static/**").addResourceLocations("/static/");
      }
  }
  </code></pre>
  
  <p>and changed link to:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" media="all" th:href="@{/static/css/cc.css}" /&gt;
  </code></pre>
  
  <p>I'm still getting the same error...</p>
  
  <p>UPDATE 2</p>
  
  <p>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:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" media="all" th:href="@{css/cc.css}" href="css/cc.css"/&gt;
  </code></pre>
  
  <p>But when I enable security it fails with 400 error. This is my config file (in a nutshell):</p>
  
  <pre><code>@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);
      }        
  }
  </code></pre>
  
  <p>So, I guess the question is, why is it loading from webapp instead of resources?</p>