title: @RequestMapping dont' work with @ResponseStatus
body: <p>I wrote this method to handle the validation of the classes:</p>
  
  <pre><code>@RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(MethodArgumentNotValidException.class)
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  public @ResponseBody ResultDTO handleValidationException(MethodArgumentNotValidException ex) throws IOException {
      ResultDTO result = new ResultDTO();
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Validation Failure");
      map.put("violations", convertConstraintViolation(ex));
      result.setMap(map);
      return result;
  }
  </code></pre>
  
  <p>When an exception occurs, the method returns the HttpStatus.BAD_REQUEST but does not return the @ResponseBody.
  Why? Thank you!</p>
  
  <p>UPDATE:</p>
  
  <p>This is my handling class:</p>
  
  <pre><code>package it.cle.project.validation;
  import it.cle.project.dto.ResultDTO;
  import java.io.IOException;
  import java.util.Map;
  import java.util.Set;
  import javax.validation.ConstraintViolation;
  import javax.validation.ConstraintViolationException;
  import org.springframework.dao.DataAccessException;
  import org.springframework.dao.DataIntegrityViolationException;
  import org.springframework.http.HttpStatus;
  import org.springframework.orm.ObjectRetrievalFailureException;
  import org.springframework.validation.ObjectError;
  import org.springframework.web.HttpMediaTypeNotSupportedException;
  import org.springframework.web.HttpRequestMethodNotSupportedException;
  import org.springframework.web.bind.MethodArgumentNotValidException;
  import org.springframework.web.bind.MissingServletRequestParameterException;
  import org.springframework.web.bind.ServletRequestBindingException;
  import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
  import org.springframework.web.bind.annotation.ControllerAdvice;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.ResponseStatus;
  import com.google.common.collect.Maps;
  
  @ControllerAdvice
  public class DefaultExceptionHandler {
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler({MissingServletRequestParameterException.class,
          UnsatisfiedServletRequestParameterException.class,
          HttpRequestMethodNotSupportedException.class,
          ServletRequestBindingException.class
  })
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  public @ResponseBody ResultDTO handleRequestException(Exception ex) {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Request Error");
      map.put("cause", ex.getMessage());
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(ConstraintViolationException.class)
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  public @ResponseBody ResultDTO handleValidationException(ConstraintViolationException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Validation Failure");
      map.put("violations", convertConstraintViolation(ex.getConstraintViolations()));
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(MethodArgumentNotValidException.class)
  @ResponseStatus(value = HttpStatus.BAD_REQUEST)
  public @ResponseBody ResultDTO handleValidationException(MethodArgumentNotValidException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Validation Failure");
      map.put("violations", convertConstraintViolation(ex));
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(ObjectRetrievalFailureException.class)
  @ResponseStatus(value = HttpStatus.NOT_FOUND)
  public @ResponseBody ResultDTO handleValidationException(ObjectRetrievalFailureException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Entity Not Found");
      map.put("cause", ex.getMessage());
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(DataIntegrityViolationException.class)
  @ResponseStatus(value = HttpStatus.CONFLICT)
  public @ResponseBody ResultDTO handleDataIntegrityViolationException(DataIntegrityViolationException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Data Integrity Error");
      map.put("cause", ex.getCause().getCause().getLocalizedMessage());
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(DataAccessException.class)
  @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
  public @ResponseBody ResultDTO handleDataAccessException(DataAccessException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Data Error");
      map.put("cause", ex.getCause().getMessage());
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(HttpMediaTypeNotSupportedException.class)
  @ResponseStatus(value = HttpStatus.UNSUPPORTED_MEDIA_TYPE)
  public @ResponseBody ResultDTO handleUnsupportedMediaTypeException(HttpMediaTypeNotSupportedException ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Unsupported Media Type");
      map.put("cause", ex.getLocalizedMessage());
      map.put("supported", ex.getSupportedMediaTypes());
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  @RequestMapping(produces = {"application/vnd.captech-v1.0+json", "application/vnd.captech-v2.0+json"})
  @ExceptionHandler(Exception.class)
  @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
  public @ResponseBody ResultDTO handleUncaughtException(Exception ex) throws IOException {
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
      map.put("error", "Unknown Error");
      if (ex.getCause() != null) {
          map.put("cause", ex.getCause().getMessage());
      } else {
          map.put("cause", ex.getMessage());
      }
      ResultDTO result = new ResultDTO();
      result.setMap(map);
      return result;
  }
  
  private Map&lt;String, Map&lt;String, Object&gt; &gt; convertConstraintViolation(Set&lt;ConstraintViolation&lt;?&gt;&gt; constraintViolations) {
      Map&lt;String, Map&lt;String, Object&gt; &gt; result = Maps.newHashMap();
      for (ConstraintViolation constraintViolation : constraintViolations) {
          Map&lt;String, Object&gt;  violationMap = Maps.newHashMap();
          violationMap.put("value", constraintViolation.getInvalidValue());
          violationMap.put("type", constraintViolation.getRootBeanClass());
          violationMap.put("message", constraintViolation.getMessage());
          result.put(constraintViolation.getPropertyPath().toString(), violationMap);
      }
      return result;
  }
  
  private Map&lt;String, Map&lt;String, Object&gt; &gt; convertConstraintViolation(MethodArgumentNotValidException ex) {
      Map&lt;String, Map&lt;String, Object&gt; &gt; result = Maps.newHashMap();
      for (ObjectError error : ex.getBindingResult().getAllErrors()) {
          Map&lt;String, Object&gt;  violationMap = Maps.newHashMap();
          violationMap.put("target", ex.getBindingResult().getTarget());
          violationMap.put("type", ex.getBindingResult().getTarget().getClass());
          violationMap.put("message", error.getDefaultMessage());
          result.put(error.getObjectName(), violationMap);
      }
      return result;
  }
  }
  </code></pre>
  
  <p>When I call (with wrong params) my method, the handleValidationException(ConstraintViolationException ex) method is called.
  My method validate the IndiceBarthel entity and throw exception.</p>
  
  <pre><code>@RequestMapping(value = "/indiceBarthel", method = RequestMethod.POST)
  public ResultDTO createIndiceBarthel(@Valid @RequestBody IndiceBarthel indiceBarthel) throws Exception {
  
      ResultDTO result = new ResultDTO();
      Map&lt;String, Object&gt;  map = Maps.newHashMap();
  
      try {
          ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
          IndiceBarthelService indiceBarthelService = (IndiceBarthelService) context.getBean("indiceBarthelService");
          indiceBarthelService.createIndiceBarthel(indiceBarthel);
  
      } catch (Exception e) {
          throw new Exception();
      }
  
  
      map.put("result", "Inserimento effettuato");
      map.put("entity", indiceBarthel);
  
  
      result.setMap(map);
      return result;
  }
  </code></pre>
  
  <p>UPDATE:
  I do not know why, but the problem depends on the method invocation: if I call from RESTClient (debugger for RESTful web services) is ok, otherwise if I call from RestTemplate returns a 404 error, crashes and does not return the JSON error...</p>