jeudi 12 mars 2015

Spring @ExceptionHandler not handling Hibernate's javax.validation.ConstraintViolationException

I'm using Hibernate Validator with Spring to validate my entities, and I have the following bean that validates entities and throws a javax.validation.ConstraintViolationException in case something is invalid:


http://ift.tt/1EgqdOj


I'm using this method from a Service, and letting it all pass through the following class that handles the given exceptions, specially this one as you can see in the line provided:


http://ift.tt/1L58bVP


Debugging that code, I can even see the above method being executed, with the right exception passed and everything, but instead of a 400 Bad Request and a nice array with the constraint violations, I'm getting a 500 Internal Server Error with the message: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.validation.ConstraintViolationException.


And with that my unit tests results in an error.


As for the other exceptions that I created, like this one:


http://ift.tt/1EgqgcQ


They're being handled just fine, and returns a 404 Not Found.


Can someone help me? I'm not using Spring Boot, just basic XML config app.


Aucun commentaire:

Enregistrer un commentaire