title: Spring MVC PUT Request returns 405 Method Not Allowed
body: <p>I am using spring mvc to set up a rest api and most of the configurations are set up automatically through the spring boot project. On the front end I am using angularjs and their $http module to make ajax requests to the server for resources. Resource urls are defined in my controller class but only the GET urls are being matched.  I've tried PUT and POST but these return 405 method not allowed and 403 forbidden respectively. </p>
  
  <p>My controller looks like this</p>
  
  <pre><code>@Controller
  @RequestMapping("/api/users")
  public class UserController {
  
      @Inject
      UserService svc;
  
      @RequestMapping(method = RequestMethod.GET)
      @ResponseBody
      public List&lt;User&gt; home() {
          return svc.findAll();
      }
  
      @RequestMapping(method = RequestMethod.GET, value = "/{id}")
      @ResponseBody
      public User findById(@PathVariable long id){
          return svc.findById(id);
      }
  
      @RequestMapping(method = RequestMethod.PUT, value="/{id}")
      @ResponseBody
      public User updateUser(@PathVariable long id, @RequestBody User user){
          Assert.isTrue(user.getId().equals(id), "User Id must match Url Id");
          return svc.updateUser(id, user);
      }
  
  }
  </code></pre>
  
  <p>and the request to the server that is not matching the url looks like this</p>
  
  <pre><code>$http({
              url: BASE_API + 'users/' + user.id,
              method: 'PUT',
              data:user
          })
  </code></pre>
  
  <p>this produces a PUT request to localhost:8080/api/users/1 and the server responds with a 405 Method Not Allowed response code.</p>
  
  <p>The same request mapping but with a RequestMethod.GET is correctly handled when the server receives an HTTP GET request to localhost:8080/api/users/1</p>
  
  <p>Any insight would really help.</p>
  
  <p>PS in case this is needed the included spring boot dependencies are </p>
  
  <pre><code>    &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-security&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-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&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-tomcat&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Thanks</p>