异常处理
Spring MVC异常处理
Restlight for Spring MVC支持使用Spring MVC中的@ExceptionHandler
, @ControllerAdvice
等注解,并且对此能力进行了增强
参考ExceptionHandler支持
Note
仅在项目引入了restlight-springmvc-provider
依赖的情况下使用(默认引入)
ExceptionResolver
eg.
处理RuntimeException
@Component
public class GlobalExceptionResolver implements ExceptionResolver<RuntimeException> {
@Override
public CompletableFuture<Void> handleException(AsyncRequest request,
AsyncResponse response,
RuntimeException e) {
// handle exception here
return CompletableFuture.completedFuture(null);
}
}
Tip
处理不同异常类型实现不同的ExceptionResolver<T extends Throwable>
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified July 28, 2022: refactor main docs to v0.1.1 (#199) (8423db1)