Polish @ControllerAdvice and @RestControllerAdvice
This commit is contained in:
@@ -74,11 +74,11 @@ public @interface ControllerAdvice {
|
||||
|
||||
/**
|
||||
* Alias for the {@link #basePackages} attribute.
|
||||
* <p>Allows for more concise annotation declarations e.g.:
|
||||
* <p>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.
|
||||
* <p>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"})}.
|
||||
* <p>{@link #value} is an alias for this attribute, simply allowing for
|
||||
* more concise use of the annotation.
|
||||
* <p>Also consider using {@link #basePackageClasses()} as a type-safe
|
||||
* <p>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.
|
||||
* <p>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.
|
||||
* <p>Controllers that are annotated with at least one of the supplied annotation
|
||||
* types will be advised by the {@code @ControllerAdvice} annotated class.
|
||||
* <p>Consider creating a custom composed annotation or use a predefined one,
|
||||
* like {@link RestController @RestController}.
|
||||
* @since 4.0
|
||||
|
||||
@@ -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.
|
||||
* <p>Allows for more concise annotation declarations e.g.:
|
||||
* {@code @ControllerAdvice("org.my.pkg")} is equivalent to
|
||||
* {@code @ControllerAdvice(basePackages="org.my.pkg")}.
|
||||
* @see #basePackages()
|
||||
* <p>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.
|
||||
* <p>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"})}.
|
||||
* <p>{@link #value} is an alias for this attribute, simply allowing for
|
||||
* more concise use of the annotation.
|
||||
* <p>Also consider using {@link #basePackageClasses()} as a type-safe
|
||||
* <p>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.
|
||||
* <p>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.
|
||||
* <p>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.
|
||||
* <p>Controllers that are annotated with this/one of those annotation(s)
|
||||
* will be assisted by the {@code @ControllerAdvice} annotated class.
|
||||
* <p>Consider creating a special annotation or use a predefined one,
|
||||
* <p>Controllers that are annotated with at least one of the supplied annotation
|
||||
* types will be advised by the {@code @RestControllerAdvice} annotated class.
|
||||
* <p>Consider creating a custom composed annotation or use a predefined one,
|
||||
* like {@link RestController @RestController}.
|
||||
*/
|
||||
@AliasFor(annotation = ControllerAdvice.class)
|
||||
Class<? extends Annotation>[] annotations() default {};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user