title: Add CSS file to Spring Boot + Spring Security Thymeleaf file
body: <p>I wanted to add CSS file to my HTML file. 
  The problem appeared when I tried to add CSS to Spring Security application (I work on basic Spring Getting Started Content). I blame Spring Security because without it the CSS file loads properly.</p>
  
  <p><code>Application.java</code> file:</p>
  
  <pre class="lang-java prettyprint-override"><code>package mainpack;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) throws Throwable {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p><code>MvcConfig.java</code> file:</p>
  
  <pre class="lang-java prettyprint-override"><code>package mainpack;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  
  @Configuration
  public class MvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/home").setViewName("home");
          registry.addViewController("/").setViewName("home");
          registry.addViewController("/hello").setViewName("hello");
          registry.addViewController("/login").setViewName("login");
          registry.addViewController("/index").setViewName("index");
          registry.addViewController("/register").setViewName("register");
          registry.addViewController("/whatever").setViewName("whatever");
      }
  }
  </code></pre>
  
  <p><code>WebSecurityConfig.java</code> file:</p>
  
  <pre class="lang-java prettyprint-override"><code>package mainpack;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  
  @Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .antMatchers("/", "/home", "/index", "/register", "../static/css", "../static/images").permitAll()
                  .anyRequest().authenticated()
                  .and()
              .formLogin()
                  .loginPage("/login")
                  .permitAll()
                  .and()
              .logout()
                  .permitAll();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .inMemoryAuthentication()
                  .withUser("user").password("password").roles("USER");
      }
  }
  </code></pre>
  
  <p>I load CSS with line:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;link href="../static/css/index.css" th:href="@{/css/index.css}" rel="stylesheet" /&gt;
  </code></pre>
  
  <p>in <code>index.html</code> file.</p>