Top Description Methods
org.springframework.web.bind.annotation

public @Interface RestControllerAdvice

extends Annotation
Annotations
@Target:TYPE
@Retention:RUNTIME
@Documented
@ControllerAdvice
@ResponseBody
Imports
java.lang.annotation.Annotation, .Documented, .ElementType, .Retention, .RetentionPolicy, .Target, org.springframework.core.annotation.AliasFor

A convenience annotation that is itself annotated with @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.

Authors
Rossen Stoyanchev, Sam Brannen
Since
4.3
See Also
RestController, ControllerAdvice

Method Summary

Modifier and TypeMethod and Description
public Class<? extends Annotation>[]
annotations()

Array of annotations.

public Class<?>[]
assignableTypes()

Array of classes.

public Class<?>[]
basePackageClasses()

Type-safe alternative to basePackages for specifying the packages in which to select controllers to be advised by the @RestControllerAdvice annotated class.

public String[]
basePackages()

Array of base packages.

public String
public String[]
value()

Alias for the basePackages attribute.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

annotationsback to summary
public Class<? extends Annotation>[] annotations()

Array of annotations.

Controllers that are annotated with at least one of the supplied annotation types will be advised by the @RestControllerAdvice annotated class.

Consider creating a custom composed annotation or use a predefined one, like @RestController.

Annotations
@AliasFor
annotation:ControllerAdvice
assignableTypesback to summary
public Class<?>[] assignableTypes()

Array of classes.

Controllers that are assignable to at least one of the given types will be advised by the @RestControllerAdvice annotated class.

Annotations
@AliasFor
annotation:ControllerAdvice
basePackageClassesback to summary
public Class<?>[] basePackageClasses()

Type-safe alternative to basePackages for specifying the packages in which to select controllers to be advised by the @RestControllerAdvice annotated 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.

Annotations
@AliasFor
annotation:ControllerAdvice
basePackagesback to summary
public String[] 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.

Annotations
@AliasFor
annotation:ControllerAdvice
nameback to summary
public String name()

Alias for ControllerAdvice#name.

Annotations
@AliasFor
annotation:ControllerAdvice
Since
6.1
valueback to summary
public String[] value()

Alias for the basePackages attribute.

Allows for more concise annotation declarations — for example, @RestControllerAdvice("org.my.pkg") is equivalent to @RestControllerAdvice(basePackages = "org.my.pkg").

Annotations
@AliasFor
annotation:ControllerAdvice
See Also
basePackages