title: Spring @ExceptionHandler does not work with @ResponseBody
body: <p>I try to configure a spring exception handler for a rest controller that is able to render a map to both xml and json based on the incoming accept header. It throws a 500 servlet exception right now.</p>
  <p>This works, it picks up the home.jsp:</p>
  <pre><code>@ExceptionHandler(IllegalArgumentException.class)
  public String handleException(final Exception e, final HttpServletRequest request, Writer writer)
  {
      return &quot;home&quot;;
  }
  </code></pre>
  <p>This does not work:</p>
  <pre><code>@ExceptionHandler(IllegalArgumentException.class)
  public @ResponseBody Map&lt;String, Object&gt; handleException(final Exception e, final HttpServletRequest request, Writer writer)
  {
      final Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
      map.put(&quot;errorCode&quot;, 1234);
      map.put(&quot;errorMessage&quot;, &quot;Some error message&quot;);
      return map;
  }
  </code></pre>
  <p>In the same controller mapping the response to xml or json via the respective converter works:</p>
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = &quot;/book/{id}&quot;, headers = &quot;Accept=application/json,application/xml&quot;)
  public @ResponseBody
  Book getBook(@PathVariable final String id)
  {
      logger.warn(&quot;id=&quot; + id);
      return new Book(&quot;12345&quot;, new Date(), &quot;Sven Haiges&quot;);
  }
  </code></pre>