Sotirios Delimanolis在他的答复中非常有帮助,关于进一步调查,我们发现,在春季,3.2.4条路途上,“The Code for @ControllerAdvice note”也检查了“Order Note”的存在,并对主计长AdviceBeans名单进行了分类。
The resulting default order for all controllers without the @Order annotation is Ordered#LOWEST_PRECEDENCE which means if you have one controller that needs to be the lowest priority then ALL your controllers need to have a higher order.
这里的一个例子是,在用户档案接收或实时接收发生时,如何与主计长Advice和命令说明一起开设两个例外的手递班,以便作出适当反应。
class UserProfileException extends RuntimeException {
}
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
class UserProfileExceptionHandler {
@ExceptionHandler(UserProfileException)
@ResponseBody
ResponseEntity<ErrorResponse> handleUserProfileException() {
....
}
}
@ControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE)
class DefaultExceptionHandler {
@ExceptionHandler(RuntimeException)
@ResponseBody
ResponseEntity<ErrorResponse> handleRuntimeException() {
....
}
}
- See ControllerAdviceBean#initOrderFromBeanType()
- See ControllerAdviceBean#findAnnotatedBeans()
- See ExceptionHandlerExceptionResolver#initExceptionHandlerAdviceCache()
欢乐!