@Autowired
private DefaultErrorAttributes defaultExceptionResolver;
@ExceptionHandler(HttpMessageNotReadableException.class)
public void checkForAbort(HttpServletRequest request, HttpServletResponse response, RuntimeException exception) {
if (exception.getCause() instanceof EOFException) {
ClientAbortException abortException = new ClientAbortException(exception.getCause());
abortException.addSuppressed(exception);
try {
response.getOutputStream().close();
}
catch (IOException ex) {
abortException.addSuppressed(ex);
}
defaultExceptionResolver.resolveException(request, response, null, abortException);
}
else {
throw exception;
}
}
例如,这可能会进入@ControllerAdvice
。