diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java index 8a2661245a..dd59a41455 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerAdvice.java @@ -74,11 +74,11 @@ public @interface ControllerAdvice { /** * Alias for the {@link #basePackages} attribute. - *

Allows for more concise annotation declarations e.g.: + *

Allows for more concise annotation declarations — for example, * {@code @ControllerAdvice("org.my.pkg")} is equivalent to - * {@code @ControllerAdvice(basePackages="org.my.pkg")}. + * {@code @ControllerAdvice(basePackages = "org.my.pkg")}. * @since 4.0 - * @see #basePackages() + * @see #basePackages */ @AliasFor("basePackages") String[] value() default {}; @@ -86,11 +86,12 @@ public @interface ControllerAdvice { /** * Array of base packages. *

Controllers that belong to those base packages or sub-packages thereof - * will be included, e.g.: {@code @ControllerAdvice(basePackages="org.my.pkg")} - * or {@code @ControllerAdvice(basePackages={"org.my.pkg", "org.my.other.pkg"})}. + * will be included — for example, + * {@code @ControllerAdvice(basePackages = "org.my.pkg")} or + * {@code @ControllerAdvice(basePackages = {"org.my.pkg", "org.my.other.pkg"})}. *

{@link #value} is an alias for this attribute, simply allowing for * more concise use of the annotation. - *

Also consider using {@link #basePackageClasses()} as a type-safe + *

Also consider using {@link #basePackageClasses} as a type-safe * alternative to String-based package names. * @since 4.0 */ @@ -116,9 +117,9 @@ public @interface ControllerAdvice { Class[] assignableTypes() default {}; /** - * Array of annotations. - *

Controllers that are annotated with at least one of the supplied annotations - * will be advised by the {@code @ControllerAdvice} annotated class. + * Array of annotation types. + *

Controllers that are annotated with at least one of the supplied annotation + * types will be advised by the {@code @ControllerAdvice} annotated class. *

Consider creating a custom composed annotation or use a predefined one, * like {@link RestController @RestController}. * @since 4.0 diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java index 9e3ab4afa3..e06bb6f124 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ import org.springframework.core.annotation.AliasFor; * which are the default in the MVC Java config and the MVC namespace. * * @author Rossen Stoyanchev + * @author Sam Brannen * @since 4.3 * @see RestController * @see ControllerAdvice @@ -53,50 +54,54 @@ public @interface RestControllerAdvice { /** * Alias for the {@link #basePackages} attribute. - *

Allows for more concise annotation declarations e.g.: - * {@code @ControllerAdvice("org.my.pkg")} is equivalent to - * {@code @ControllerAdvice(basePackages="org.my.pkg")}. - * @see #basePackages() + *

Allows for more concise annotation declarations — for example, + * {@code @RestControllerAdvice("org.my.pkg")} is equivalent to + * {@code @RestControllerAdvice(basePackages = "org.my.pkg")}. + * @see #basePackages */ - @AliasFor("basePackages") + @AliasFor(annotation = ControllerAdvice.class) String[] value() default {}; /** * Array of base packages. *

Controllers that belong to those base packages or sub-packages thereof - * will be included, e.g.: {@code @ControllerAdvice(basePackages="org.my.pkg")} - * or {@code @ControllerAdvice(basePackages={"org.my.pkg", "org.my.other.pkg"})}. + * will be included — for example, + * {@code @RestControllerAdvice(basePackages = "org.my.pkg")} or + * {@code @RestControllerAdvice(basePackages = {"org.my.pkg", "org.my.other.pkg"})}. *

{@link #value} is an alias for this attribute, simply allowing for * more concise use of the annotation. - *

Also consider using {@link #basePackageClasses()} as a type-safe + *

Also consider using {@link #basePackageClasses} as a type-safe * alternative to String-based package names. */ - @AliasFor("value") + @AliasFor(annotation = ControllerAdvice.class) String[] basePackages() default {}; /** - * Type-safe alternative to {@link #value()} for specifying the packages - * to select Controllers to be assisted by the {@code @ControllerAdvice} + * Type-safe alternative to {@link #basePackages} for specifying the packages + * in which to select controllers to be advised by the {@code @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. */ + @AliasFor(annotation = ControllerAdvice.class) Class[] basePackageClasses() default {}; /** * Array of classes. *

Controllers that are assignable to at least one of the given types - * will be assisted by the {@code @ControllerAdvice} annotated class. + * will be advised by the {@code @RestControllerAdvice} annotated class. */ + @AliasFor(annotation = ControllerAdvice.class) Class[] assignableTypes() default {}; /** * Array of annotations. - *

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

Consider creating a special annotation or use a predefined one, + *

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

Consider creating a custom composed annotation or use a predefined one, * like {@link RestController @RestController}. */ + @AliasFor(annotation = ControllerAdvice.class) Class[] annotations() default {}; }