title: Spring default consumes and produces
body: <p>I'm writing a servlet that will use a bunch of RestControllers to provide functionality.</p>
  
  <p>All of that will use JSON almost exclusively, so I would like a compact way to say: Unless specified otherwise, consume and produce MediaType.APPLICATION_JSON_VALUE for everything.</p>
  
  <p>I thought I found a nice solution <a href="https://stackoverflow.com/a/35183405/2436002">on another SO question</a>.</p>
  
  <p>However, as already pointed out in <a href="https://stackoverflow.com/questions/35123835/spring-requestmapping-for-controllers-that-produce-and-consume-json#comment89477050_35183405">a comment there</a>, this solution causes trouble.</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/relationship/type", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, method = {
          RequestMethod.GET
       })
  public class DRelationshipTypeResource {
  
      // @GetMapping("/all")
      @RequestMapping(value = "/all", method = RequestMethod.GET)
      public List&lt;DRelationshipTypeDTO&gt; getAll() {
          return DRelationshipTypeService.getAll();
      }
  </code></pre>
  
  <p>This controller also will feature POST/PUT/DELETE plus some more GETs. I removed them for now to minimize possible causes of errors.</p>
  
  <p>Calling this route produces a 415 error.</p>
  
  <p>Even worse, I would really like to be able to use</p>
  
  <pre><code>@GetMapping("/all")
  </code></pre>
  
  <p>instead of the more verbose @RequestMapping Overload for the getAll()-Method, but that also produces the same 415 error.</p>
  
  <p>Server debug console spits out this when the request arrives:</p>
  
  <pre><code>2019-01-29 10:20:54.627  WARN 10712 --- [io-9999-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported]
  
  2019-01-29 10:20:54.628 ERROR 10712 --- [io-9999-exec-10] o.a.c.c.C.[Tomcat].[localhost]           : Exception Processing ErrorPage[errorCode=0, location=/error]
  
  java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
      at org.apache.catalina.core.ApplicationHttpRequest.setRequest(ApplicationHttpRequest.java:690) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.ApplicationHttpRequest.&lt;init&gt;(ApplicationHttpRequest.java:114) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:917) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:358) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:394) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:175) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.14.jar:9.0.14]
      at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
  </code></pre>
  
  <p>and returns a HTTP Status 415 – Unsupported Media Type to the client making the request.</p>
  
  <p>To clarify further, if I use a "dumb" class such as this, everything works fine, with the content correctly being returned as JSON.</p>
  
  <pre><code>@RestController
  @RequestMapping("relationship/type")
  public class DRelationshipTypeResource {
  
      @GetMapping("/all")
      public List&lt;DRelationshipTypeDTO&gt; getAll() {
          return DRelationshipTypeService.getAll();
      }
  </code></pre>