注释类型 RestControllerAdvice
@Target(TYPE) @Retention(RUNTIME) @Documented @ControllerAdvice @ResponseBody public @interface RestControllerAdvice
A convenience annotation that is itself annotated with@ControllerAdviceand@ResponseBody.Types that carry this annotation are treated as controller advice where
@ExceptionHandlermethods assume@ResponseBodysemantics by default.NOTE:
@RestControllerAdviceis processed if an appropriateHandlerMapping-HandlerAdapterpair is configured such as theRequestMappingHandlerMapping-RequestMappingHandlerAdapterpair which are the default in the MVC Java config and the MVC namespace. In particular@RestControllerAdviceis not supported with theDefaultAnnotationHandlerMapping-AnnotationMethodHandlerAdapterpair both of which are also deprecated.- 从以下版本开始:
- 4.3
- 作者:
- Rossen Stoyanchev
可选元素概要
可选元素 修饰符和类型 可选元素 说明 Class<? extends Annotation>[]annotationsArray of annotations.Class<?>[]assignableTypesArray of classes.Class<?>[]basePackageClassesType-safe alternative tovalue()for specifying the packages to select Controllers to be assisted by the@ControllerAdviceannotated class.String[]basePackagesArray of base packages.String[]valueAlias for thebasePackages()attribute.
元素详细资料
value
@AliasFor("basePackages") String[] value
Alias for thebasePackages()attribute.Allows for more concise annotation declarations e.g.:
@ControllerAdvice("org.my.pkg")is equivalent to@ControllerAdvice(basePackages="org.my.pkg").- 另请参阅:
basePackages()
- 默认值:
- {}
basePackages
@AliasFor("value") String[] basePackages
Array of base packages.Controllers that belong to those base packages or sub-packages thereof will be included, e.g.:
@ControllerAdvice(basePackages="org.my.pkg")or@ControllerAdvice(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
Class<?>[] basePackageClasses
Type-safe alternative tovalue()for specifying the packages to select Controllers to be assisted by the@ControllerAdviceannotated 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
Class<?>[] assignableTypes
Array of classes.Controllers that are assignable to at least one of the given types will be assisted by the
@ControllerAdviceannotated class.- 默认值:
- {}
annotations
Class<? extends Annotation>[] annotations
Array of annotations.Controllers that are annotated with this/one of those annotation(s) will be assisted by the
@ControllerAdviceannotated class.Consider creating a special annotation or use a predefined one, like
@RestController.- 默认值:
- {}