Skip to content

Commit ad915f4

Browse files
committed
Document that Ordered is not supported for @ControllerAdvice beans
Closes gh-23172
1 parent bcad276 commit ad915f4

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,31 +32,29 @@
3232
* {@link ModelAttribute @ModelAttribute} methods to be shared across
3333
* multiple {@code @Controller} classes.
3434
*
35-
* <p>Classes with {@code @ControllerAdvice} can be declared explicitly as Spring
36-
* beans or auto-detected via classpath scanning. All such beans are sorted via
37-
* {@link org.springframework.core.annotation.AnnotationAwareOrderComparator
38-
* AnnotationAwareOrderComparator}, i.e. based on
39-
* {@link org.springframework.core.annotation.Order @Order} and
40-
* {@link org.springframework.core.Ordered Ordered}, and applied in that order
41-
* at runtime. For handling exceptions, an {@code @ExceptionHandler} will be
42-
* picked on the first advice with a matching exception handler method. For
43-
* model attributes and {@code InitBinder} initialization, {@code @ModelAttribute}
44-
* and {@code @InitBinder} methods will also follow {@code @ControllerAdvice} order.
35+
* <p>Classes annotated with {@code @ControllerAdvice} can be declared explicitly
36+
* as Spring beans or auto-detected via classpath scanning. All such beans are
37+
* sorted based on {@link org.springframework.core.annotation.Order @Order}
38+
* semantics and applied in that order at runtime. For handling exceptions, an
39+
* {@code @ExceptionHandler} will be picked on the first advice with a matching
40+
* exception handler method. For model attributes and {@code InitBinder}
41+
* initialization, {@code @ModelAttribute} and {@code @InitBinder} methods will
42+
* also follow {@code @ControllerAdvice} order.
4543
*
4644
* <p>Note: For {@code @ExceptionHandler} methods, a root exception match will be
4745
* preferred to just matching a cause of the current exception, among the handler
4846
* methods of a particular advice bean. However, a cause match on a higher-priority
49-
* advice will still be preferred to a any match (whether root or cause level)
47+
* advice will still be preferred over any match (whether root or cause level)
5048
* on a lower-priority advice bean. As a consequence, please declare your primary
51-
* root exception mappings on a prioritized advice bean with a corresponding order!
49+
* root exception mappings on a prioritized advice bean with a corresponding order.
5250
*
5351
* <p>By default the methods in an {@code @ControllerAdvice} apply globally to
54-
* all Controllers. Use selectors {@link #annotations()},
55-
* {@link #basePackageClasses()}, and {@link #basePackages()} (or its alias
56-
* {@link #value()}) to define a more narrow subset of targeted Controllers.
57-
* If multiple selectors are declared, OR logic is applied, meaning selected
58-
* Controllers should match at least one selector. Note that selector checks
59-
* are performed at runtime and so adding many selectors may negatively impact
52+
* all controllers. Use selectors such as {@link #annotations},
53+
* {@link #basePackageClasses}, and {@link #basePackages} (or its alias
54+
* {@link #value}) to define a more narrow subset of targeted controllers.
55+
* If multiple selectors are declared, {@code OR} logic is applied, meaning selected
56+
* controllers should match at least one selector. Note that selector checks
57+
* are performed at runtime, so adding many selectors may negatively impact
6058
* performance and add complexity.
6159
*
6260
* @author Rossen Stoyanchev

0 commit comments

Comments
 (0)