title: Spring boot with authentication - login page not found (404)
body: <p>I have a problem with my spring application since I've tried to include some security things.</p>
  
  <p>After building a small working app including angularJS I followed this <a href="http://justinrodenbostel.com/2014/05/30/part-5-integrating-spring-security-with-spring-boot-web/" rel="noreferrer">spring security tutorial</a> but I can't get it started. When I try to access any part of the app, the security modul wants to redirect to <a href="http://localhost:8080/login" rel="noreferrer">http://localhost:8080/login</a>... but can't find it. </p>
  
  <blockquote>
    <p>There was an unexpected error (type=Not Found, status=404).
    No message available</p>
  </blockquote>
  
  <p>Maybe I'm just missing a small thing but I can't figure out what it is ^^</p>
  
  <p>Here is my code...</p>
  
  <p><strong>folder structure:</strong></p>
  
  <pre><code>src/main/java
   +-Application.java
   +-SecurityConfiguration.java
  
  src/main/resources
   +-static
    +-index.html
   +-templates
    +-login.html
  </code></pre>
  
  <p><strong>pom.xml:</strong></p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.3.0.BUILD-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;!-- Additional lines to be added here... --&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;9.3-1100-jdbc4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.googlecode.json-simple&lt;/groupId&gt;
          &lt;artifactId&gt;json-simple&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>Application.java:</strong></p>
  
  <pre><code>import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
  
  @Configuration
  @EnableAutoConfiguration
  @ComponentScan
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/login").setViewName("login");
      }
  }
  </code></pre>
  
  <p><strong>SecurityConfiguration.java:</strong></p>
  
  <pre><code>    import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  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.servlet.configuration.EnableWebMvcSecurity;
  import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
  
  @Configuration
  @EnableWebMvcSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
                  .authorizeRequests().anyRequest().authenticated();
          http
                  .formLogin().failureUrl("/login?error")
                  .defaultSuccessUrl("/")
                  .loginPage("/login")
                  .permitAll()
                  .and()
                  .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login")
                  .permitAll();
      }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
      }
  }
  </code></pre>
  
  <p><strong>login.html:</strong></p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"&gt;
  &lt;head&gt;
  &lt;title&gt;Spring Security Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div th:if="${param.error}"&gt;Invalid username and password.&lt;/div&gt;
      &lt;div th:if="${param.logout}"&gt;You have been logged out.&lt;/div&gt;
      &lt;form th:action="@{/login}" method="post"&gt;
          &lt;div&gt;
              &lt;label&gt; User Name : &lt;input type="text" name="username" /&gt;
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;label&gt; Password: &lt;input type="password" name="password" /&gt;
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;input type="submit" value="Sign In" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>