Explicit notes on ExceptionHandler root vs cause resolution

Issue: SPR-16074
This commit is contained in:
Juergen Hoeller
2017-10-18 12:18:30 +02:00
parent ba74e42808
commit ea00c7c6c8
2 changed files with 26 additions and 15 deletions

View File

@@ -26,7 +26,6 @@ import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;
/**
* Specialization of {@link Component @Component} for classes that declare
* {@link ExceptionHandler @ExceptionHandler}, {@link InitBinder @InitBinder}, or
@@ -39,10 +38,17 @@ import org.springframework.stereotype.Component;
* AnnotationAwareOrderComparator}, i.e. based on
* {@link org.springframework.core.annotation.Order @Order} and
* {@link org.springframework.core.Ordered Ordered}, and applied in that order
* at runtime. For handling exceptions the first {@code @ExceptionHandler} to
* match the exception is used. For model attributes and {@code InitBinder}
* initialization, {@code @ModelAttribute} and {@code @InitBinder} methods will
* also follow {@code @ControllerAdvice} order.
* at runtime. For handling exceptions, an {@code @ExceptionHandler} will be
* picked on the first advice with a matching exception handler method. For
* model attributes and {@code InitBinder} initialization, {@code @ModelAttribute}
* and {@code @InitBinder} methods will also follow {@code @ControllerAdvice} order.
*
* <p>Note: For {@code @ExceptionHandler} methods, a root exception match will be
* preferred to just matching a cause of the current exception, among the handler
* methods of a particular advice bean. However, a cause match on a higher-priority
* advice will still be preferred to a any match (whether root or cause level)
* on a lower-priority advice bean. As a consequence, please declare your primary
* root exception mappings on a prioritized advice bean with a corresponding order!
*
* <p>By default the methods in an {@code @ControllerAdvice} apply globally to
* all Controllers. Use selectors {@link #annotations()},