title: Spring @ExceptionHandler - apply to json producing @RequestMapping only
body: <p>I have an exception handler like this that will produce a json error object to be consumed by javascript in the view.</p>
  
  <pre><code>@ControllerAdvice
  public class ExceptionHandlerController {
  
  
      @ExceptionHandler(value = Exception.class)
      @ResponseBody
      public final JsonResponse&lt;Void&gt; handleJsonException(
              final Exception e,
              final HttpServletRequest request,
              final HttpServletResponse response) {
          response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
          return new ErrorJsonResponse(e);
      }
  
  }
  </code></pre>
  
  <p>I don't want this method to run for regular postback (non json) requests.  So I would like to have these sorts of exception handled by the WEB.XML configured error pages.</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/500&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>In my @RequestMapping methods that return json I explicitly set the produces value.</p>
  
  <pre><code>@RequestMapping(value = "/dosomething",
          method = RequestMethod.POST,
          produces = MediaType.APPLICATION_JSON_VALUE)
  </code></pre>
  
  <p>How can I tell spring to use a particular exception handler based on the produces content type?</p>