我正在尝试重写该handleMethodArgumentNotValid方法。但我仍然收到错误:
Caused by: java.lang.IllegalStateException: Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]
我已经按照各种帖子中的建议覆盖了该方法(例如在Spring Rest ErrorHandling @ControllerAdvice / @Valid中),如下所示:
@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class CustomExceptionHandler extends ResponseEntityExceptionHandler {
@Override
@ExceptionHandler(value = MethodArgumentNotValidException.class)
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest webRequest) {
String message = errorMessageBuilder(ex);
return handleExceptionInternal(ex, message, new HttpHeaders(), HttpStatus.UNPROCESSABLE_ENTITY, webRequest);
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
真挚地,
马塞尔