org.springframework.web.bind.annotation

Annotation Type RestControllerAdvice



  • @Target(value=TYPE)
     @Retention(value=RUNTIME)
     @Documented
     @ControllerAdvice
     @ResponseBody
    public @interface RestControllerAdvice
    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.

    Since:
    4.3
    Author:
    Rossen Stoyanchev
    See Also:
    RestController, ControllerAdvice
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element and Description
      java.lang.Class<? extends java.lang.annotation.Annotation>[] annotations
      Array of annotations.
      java.lang.Class<?>[] assignableTypes
      Array of classes.
      java.lang.Class<?>[] basePackageClasses
      Type-safe alternative to value() for specifying the packages to select Controllers to be assisted by the @ControllerAdvice annotated class.
      java.lang.String[] basePackages
      Array of base packages.
      java.lang.String[] value
      Alias for the basePackages() attribute.
    • Element Detail

      • value

        @AliasFor(value="basePackages")
        public abstract java.lang.String[] value
        Alias for the basePackages() attribute.

        Allows for more concise annotation declarations e.g.: @ControllerAdvice("org.my.pkg") is equivalent to @ControllerAdvice(basePackages="org.my.pkg").

        See Also:
        basePackages()
        Default:
        {}
      • basePackages

        @AliasFor(value="value")
        public abstract java.lang.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.

        Default:
        {}
      • basePackageClasses

        public abstract java.lang.Class<?>[] basePackageClasses
        Type-safe alternative to value() for specifying the packages to select Controllers to be assisted by the @ControllerAdvice 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

        public abstract java.lang.Class<?>[] assignableTypes
        Array of classes.

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

        Default:
        {}
      • annotations

        public abstract java.lang.Class<? extends java.lang.annotation.Annotation>[] annotations
        Array of annotations.

        Controllers that are annotated with this/one of those annotation(s) will be assisted by the @ControllerAdvice annotated class.

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

        Default:
        {}