I\'m trying to handle MethodArgumentNotValidException using @ControllerAdvice as code given below:
@ControllerAdvice
public class RestResponseEntityException
Springs ResponseEntityExceptionHandler has a method handleException which is annotated with :
@ExceptionHandler({
...
MethodArgumentNotValidException.class,
...
})
Your method handleMethodArgumentNotValidException is also annotated to handle MethodArgumentNotValidException. So spring finds two methods that should be used to handle the same exception, that is the reason for the exception.
**Solution ** Do not add a new method handleMethodArgumentNotValidException instead just override the method ResponseEntityExceptionHandler.handleMethodArgumentNotValid , and do not annotate it. Your class ErrorWrapper must extend ResponseEntity for that.