Annotation Interface RestControllerAdvice
@ControllerAdvice
and @ResponseBody.
Types that carry this annotation are treated as controller advice where
@ExceptionHandler methods assume
@ResponseBody semantics by default.
NOTE: @RestControllerAdvice is processed if an appropriate
HandlerMapping-HandlerAdapter pair is configured such as the
RequestMappingHandlerMapping-RequestMappingHandlerAdapter pair
which are the default in the MVC Java config and the MVC namespace.
- 从以下版本开始:
- 2.3.7 2019-06-18 14:27
- 作者:
- Rossen Stoyanchev, Sam Brannen, Harry Yang
- 另请参阅:
-
可选元素概要
可选元素修饰符和类型可选元素说明Class<? extends Annotation>[]Array of annotations.Class<?>[]Array of classes.Class<?>[]Type-safe alternative tobasePackages()for specifying the packages in which to select controllers to be advised by the@RestControllerAdviceannotated class.String[]Array of base packages.String[]Alias forControllerAdvice.name().String[]Alias for thebasePackages()attribute.
-
元素详细资料
-
name
Alias forControllerAdvice.name().- 从以下版本开始:
- 4.0
- 默认值:
- {}
-
value
Alias for thebasePackages()attribute.Allows for more concise annotation declarations — for example,
@RestControllerAdvice("org.my.pkg")is equivalent to@RestControllerAdvice(basePackages = "org.my.pkg").- 另请参阅:
- 默认值:
- {}
-
basePackages
Array of base packages.Controllers that belong to those base packages or sub-packages thereof will be included — for example,
@RestControllerAdvice(basePackages = "org.my.pkg")or@RestControllerAdvice(basePackages = {"org.my.pkg", "org.my.other.pkg"}).value()is an alias for this attribute, simply allowing for more concise use of the annotation.Also consider using
basePackageClasses()as a type-safe alternative to String-based package names.- 默认值:
- {}
-
basePackageClasses
Type-safe alternative tobasePackages()for specifying the packages in which to select controllers to be advised by the@RestControllerAdviceannotated class.Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.
- 默认值:
- {}
-
assignableTypes
Array of classes.Controllers that are assignable to at least one of the given types will be advised by the
@RestControllerAdviceannotated class.- 默认值:
- {}
-
annotations
Array of annotations.Controllers that are annotated with at least one of the supplied annotation types will be advised by the
@RestControllerAdviceannotated class.Consider creating a custom composed annotation or use a predefined one, like
@RestController.- 默认值:
- {}
-