使用 @RestControllerAdvice
和 @ExceptionHandler
进行的异常处理,处理成 R
结构。
通用异常
- 高优先级的异常(不能再自定义)
MissingServletRequestParameterException.class
MethodArgumentTypeMismatchException.class
MethodArgumentNotValidException.class
BindException.class
ConstraintViolationException.class
NoHandlerFoundException.class
HttpMessageNotReadableException.class
HttpRequestMethodNotSupportedException.class
HttpMediaTypeNotSupportedException.class
HttpMediaTypeNotAcceptableException.class
|
- 低优先级的异常(可自定义重写)
ServiceException.class
Throwable.class
|
未知异常监听
对 ServiceException 和 Throwable 非自定义的异常可以监听 Event。
@Configuration public class MicaErrorEventListener {
@Async @EventListener(MicaErrorEvent.class) public void handleError(MicaErrorEvent event) {
}
}
|
微信公众号

精彩内容每日推荐!!!