title: Spring MVC Request Mapping passes requests that should not be passed
body: <p><strong>EDIT</strong> - This is now solved, the error was in my spring configuration. I had missed the <code>&lt;mvc:annotation-driven/&gt;</code> tag. When adding it, everything worked as expected.</p>
  
  <p>I have defined a controller using Spring MVC that should accept<code>HTTP GET</code> requests to the address <code>/controllertest</code> only if the content type of the request is <code>application/json</code>. It also returns data in <code>application/json</code>and therefore only requests that accept data in that format should pass. However, this does not work.</p>
  
  <p>This is my code using Spring 3.2.0:</p>
  
  <pre><code>package test.controllers;
  
  import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
  import static org.springframework.web.bind.annotation.RequestMethod.GET;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  @Controller
  @RequestMapping("/controllertest")
  public class TestController {
  
      @RequestMapping(method = GET, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
      @ResponseBody
      public String helloJSON() {
          return "{\"message\":\"HelloWorld\"}";  
      }
  
  }
  </code></pre>
  
  <p>This is what I expect: </p>
  
  <ol>
  <li>If I use any HTTP method other than <code>GET</code> I should receive a <code>405 - Method not allowed</code> response</li>
  <li>If I send a request that do not accept <code>application/json</code> I should receive a <code>406 Not Acceptable</code> response.</li>
  <li>If I send a request with a Content-Type other than <code>application/json</code> I should receive a <code>415 Unsupported Media Type</code> response.</li>
  </ol>
  
  <p>This is the actual result:</p>
  
  <ol>
  <li>I do actually get a <code>405 - Method not allowed</code>. Very nice.</li>
  <li>When sending a request with an <code>Accept</code> header with <code>text/xml</code> only I get a <code>200 - OK</code> response and the content type of the response is <code>text/xml</code> even though the method only produces <code>application/json</code>.</li>
  <li>When sending a request where the content type is <code>text/xml</code> I get a <code>200 - OK</code> response.</li>
  </ol>
  
  <p>I may add that I implemented all of this in Jersey and the results were all correct.</p>