title: Spring Boot Security Request method 'POST' not supported
body: <p>I am using spring boot security to handle login function. I don't know somehow the post method for login can't work at all. It will always throw the following exception.</p>
  
  <pre><code>There was an unexpected error (type=Method Not Allowed, status=405).
  Request method 'POST' not supported
  </code></pre>
  
  <p>Can somebody suggest? Here is my code. You can find it from <a href="https://github.com/hanky91/SpringBootBlog/" rel="nofollow noreferrer" title="Github">GitHub</a> as well.</p>
  
  <p>SecurityConfiguration</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Bean
      public BCryptPasswordEncoder bCryptPasswordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
      }
  }
  </code></pre>
  
  <p>HomeController</p>
  
  <pre><code>@Controller
  public class HomeController {
      @Autowired
      private UserService userService;
  
      @RequestMapping(value = { "/", "/login" }, method = RequestMethod.GET)
      public ModelAndView login(Model model) {
          ModelAndView modelAndView = new ModelAndView("auth/login");
          User user = new User();
          modelAndView.addObject(user);
          return modelAndView;
      }
  }
  </code></pre>
  
  <p>login.html</p>
  
  <pre><code>&lt;form class="form-horizontal" role="form" th:action="@{login}" method="post"&gt;
      &lt;div class="form-group"&gt;
          &lt;label class="col-md-4 control-label"&gt;Username&lt;/label&gt;
  
          &lt;div class="col-md-6"&gt;
              &lt;input type="text" class="form-control" name="username" th:placeholder="Username"/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label for="password" class="col-md-4 control-label"&gt;Password&lt;/label&gt;
  
          &lt;div class="col-md-6"&gt;
              &lt;input type="password" class="form-control" name="password" th:placeholder="Password"/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-6 col-md-offset-4"&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;
                  &lt;i class="fa fa-btn fa-sign-in"&gt;&lt;/i&gt; Login
              &lt;/button&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div align="center" th:if="${param.error}"&gt;
          &lt;p style="font-size: 20; color: #FF1C19;"&gt;Email or Password invalid, please verify&lt;/p&gt;
      &lt;/div&gt;
  &lt;/form&gt; 
  </code></pre>