title: HTTP Status 405 - Request method 'POST' not supported in Spring MVC with Spring Security
body: <p>I created a spring mvc application using freemarker template as view part. In this tried to add a model using forms.I am also using spring security
  Here is the code</p>
  
  <h2>employee.ftl</h2>
  
  <pre><code>&lt;fieldset&gt;
      &lt;legend&gt;Add Employee&lt;/legend&gt;
    &lt;form name="employee" action="addEmployee" method="post"&gt;
      Firstname: &lt;input type="text" name="name" /&gt; &lt;br/&gt;
      Employee Code: &lt;input type="text" name="employeeCode" /&gt;   &lt;br/&gt;
      &lt;input type="submit" value="   Save   " /&gt;
    &lt;/form&gt;
  </code></pre>
  
  <h2>employeeController.java</h2>
  
  <pre><code>@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
      public String addEmployee(@ModelAttribute("employee") Employee employee) {
          employeeService.add(employee);
          return "employee";
      }
  </code></pre>
  
  <h2>web.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
  &lt;!-- Spring MVC --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/spring/appServlet/servlet-context.xml,
              /WEB-INF/spring/springsecurity-servlet.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Spring Security --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <h2>Spring-security.xml</h2>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:beans="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
  
      &lt;http security="none" pattern="/resources/**"/&gt;
      &lt;!-- enable use-expressions --&gt;
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/login" access="isAnonymous()"/&gt;
          &lt;intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')" /&gt;
  
          &lt;!-- access denied page --&gt;
          &lt;access-denied-handler error-page="/403" /&gt;
          &lt;form-login 
              login-page="/login" 
              default-target-url="/"
              authentication-failure-url="/login?error" 
              username-parameter="username"
              password-parameter="password" /&gt;
          &lt;logout logout-success-url="/login?logout" /&gt;
          &lt;!-- enable csrf protection --&gt;
          &lt;csrf /&gt;
      &lt;/http&gt;
  
      &lt;authentication-manager&gt;
          &lt;authentication-provider user-service-ref="userDetailsService" &gt;
              &lt;password-encoder hash="bcrypt" /&gt;    
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>When click submit button it returns error `</p>
  
  <blockquote>
    <p>HTTP Status 405 - Request method 'POST' not supported</p>
  </blockquote>
  
  <p>`
  I gave POST method on both ftl and controller. Then why would this happen?</p>