Package org.springframework.web.bind.annotation

# Annotation Interface RestControllerAdvice

@Target(TYPE) @Retention(RUNTIME) @Documented @ControllerAdvice @ResponseBody public @interface RestControllerAdvice
A shortcut annotation that combines `@ControllerAdvice` with `@ResponseBody`, in effect simply an `@ControllerAdvice` whose exception handler methods render to the response body.

By default, `@RestControllerAdvice` applies to any controller, including `@Controller` and `@RestController`. Use attributes of the annotation to apply more specific filtering criteria.

See `ControllerAdvice` for more details.

Since:
  4.3
Author:
  Rossen Stoyanchev, Sam Brannen
See Also:
  - `RestController`
  - `ControllerAdvice`

## Optional Element Summary

Optional Elements
Modifier and Type
Optional Element
Description
`Class<? extends Annotation>[]`
`annotations`
Array of annotations.
`Class<?>[]`
`assignableTypes`
Array of classes.
`Class<?>[]`
`basePackageClasses`
Type-safe alternative to `basePackages()` for specifying the packages in which to select controllers to be advised by the `@RestControllerAdvice` annotated class.
`String[]`
`basePackages`
Array of base packages.
`String`
`name`
Alias for `ControllerAdvice.name()`.
`String[]`
`value`
Alias for the `basePackages()` attribute.

## Element Details

### name

@AliasFor(annotation=ControllerAdvice.class) String name
Alias for `ControllerAdvice.name()`.

Since:
  6.1

Default:
  ""

### value

@AliasFor(annotation=ControllerAdvice.class) 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")`.

See Also:
  - `basePackages()`

Default:
  {}

### basePackages

@AliasFor(annotation=ControllerAdvice.class) 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.

Default:
  {}

### basePackageClasses

@AliasFor(annotation=ControllerAdvice.class) 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.

Default:
  {}

### assignableTypes

@AliasFor(annotation=ControllerAdvice.class) 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.

Default:
  {}

### annotations

@AliasFor(annotation=ControllerAdvice.class) 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`.

Default:
  {}