title: handling the javax.validation.ConstraintViolationException in spring boot
body: <p>Hi I am new to spring boot.when I try submit the request from the postman it is returning <strong>org.springframework.transaction.TransactionSystemException</strong> with <strong>HttpStatus code : 500</strong> if invalid it throwing the  <strong>javax.validation.ConstraintViolationException</strong> in the server.
  Can any one share the best solution to handle these exceptions?
  I tried in controller with the below code:</p>
  <pre><code>@ExceptionHandler(ConstraintViolationException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    ResponseEntity&lt;String&gt; handleConstraintViolationException(ConstraintViolationException e) {
      return new ResponseEntity&lt;&gt;(&quot;not valid due to validation error: &quot; + e.getMessage(), HttpStatus.BAD_REQUEST);
    }
  </code></pre>
  <p>But I want the response to be send in Json format with customized error message How can I achieve it ?</p>
  <p>And also wanted to avoid the exception handling code in the controller.Is there any better way?</p>