title: Spring Boot Security custom login page
body: <p>I am wondering how I should go about creating my own custom login page? I've tried following guides such as <a href="https://docs.spring.io/spring-security/site/docs/current/guides/html5/form-javaconfig.html" rel="nofollow noreferrer">https://docs.spring.io/spring-security/site/docs/current/guides/html5/form-javaconfig.html</a> and <a href="http://www.baeldung.com/spring-mvc-tutorial#configviews" rel="nofollow noreferrer">http://www.baeldung.com/spring-mvc-tutorial#configviews</a> with no avail as I can not seem to get the <code>WebMvcConfig</code> classes to work. I keep getting 404 errors. Here are my current files</p>
  
  <p>The security configuration class</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter{
  
      /**
       * 
       */
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http.authorizeRequests().anyRequest().authenticated().and()
              .formLogin().loginPage("/login").permitAll();
          http.authorizeRequests().antMatchers("/stats").hasRole("ADMIN")
                  .and().formLogin().loginPage("/login");
          //everything else ADMIN and USERS can see
          http.authorizeRequests().antMatchers("/").hasAnyRole("ADMIN","USER")
                  .and().formLogin().loginPage("/login");     
      }
  
      @Autowired
      DataSource dataSource;
  
      @Autowired
      public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
          auth.jdbcAuthentication().dataSource(dataSource)
              .passwordEncoder(passwordEncoder());
      }
  
      @Bean
      public PasswordEncoder passwordEncoder() {
           return new BCryptPasswordEncoder();
      }
  }
  </code></pre>
  
  <p>The login.jsp file</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;HERE!!!!&lt;/h1&gt;
          &lt;form action="${contextRoot}/login" method="post"&gt;
              &lt;input type="text" name="username" value="username"/&gt;
              &lt;input type="password" name="password"/&gt;
              &lt;input type="submit" value="Login"/&gt; 
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the Web Mvc Configuration class</p>
  
  <pre><code>@EnableWebMvc
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
          registry.addViewController("/login").setViewName("login");
          registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
      }
  }
  </code></pre>