类 AnnotatedElementUtils
- java.lang.Object
- org.springframework.core.annotation.AnnotatedElementUtils
public class AnnotatedElementUtils extends Object
General utility methods for finding annotations, meta-annotations, and repeatable annotations onAnnotatedElements.AnnotatedElementUtilsdefines the public API for Spring's meta-annotation programming model with support for annotation attribute overrides. If you do not need support for annotation attribute overrides, consider usingAnnotationUtilsinstead.Note that the features of this class are not provided by the JDK's introspection facilities themselves.
Annotation Attribute Overrides
Support for meta-annotations with attribute overrides in composed annotations is provided by all variants of the
getMergedAnnotationAttributes(),getMergedAnnotation(),getAllMergedAnnotations(),getMergedRepeatableAnnotations(),findMergedAnnotationAttributes(),findMergedAnnotation(),findAllMergedAnnotations(), andfindMergedRepeatableAnnotations()methods.Find vs. Get Semantics
The search algorithms used by methods in this class follow either find or get semantics. Consult the javadocs for each individual method for details on which search algorithm is used.
Get semantics are limited to searching for annotations that are either present on an
AnnotatedElement(i.e. declared locally or inherited) or declared within the annotation hierarchy above theAnnotatedElement.Find semantics are much more exhaustive, providing get semantics plus support for the following:
- Searching on interfaces, if the annotated element is a class
- Searching on superclasses, if the annotated element is a class
- Resolving bridged methods, if the annotated element is a method
- Searching on methods in interfaces, if the annotated element is a method
- Searching on methods in superclasses, if the annotated element is a method
Support for
@InheritedMethods following get semantics will honor the contract of Java's
@Inheritedannotation except that locally declared annotations (including custom composed annotations) will be favored over inherited annotations. In contrast, methods following find semantics will completely ignore the presence of@Inheritedsince the find search algorithm manually traverses type and method hierarchies and thereby implicitly supports annotation inheritance without a need for@Inherited.- 从以下版本开始:
- 4.0
- 作者:
- Phillip Webb, Juergen Hoeller, Sam Brannen
- 另请参阅:
AliasFor,AnnotationAttributes,AnnotationUtils,BridgeMethodResolver
构造器概要
构造器 构造器 说明 AnnotatedElementUtils()
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static <A extends Annotation>
Set<A>findAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType)Find all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static <A extends Annotation>
AfindMergedAnnotation(AnnotatedElement element, Class<A> annotationType)Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.static <A extends Annotation>
AfindMergedAnnotation(AnnotatedElement element, String annotationName)已过时。As of Spring Framework 4.2.3, usefindMergedAnnotation(AnnotatedElement, Class)instead.static AnnotationAttributesfindMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static AnnotationAttributesfindMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)Find the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static <A extends Annotation>
Set<A>findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static <A extends Annotation>
Set<A>findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, Class<? extends Annotation> containerType)Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static AnnotatedElementforAnnotations(Annotation... annotations)Build an adaptedAnnotatedElementfor the given annotations, typically for use with other methods onAnnotatedElementUtils.static MultiValueMap<String,Object>getAllAnnotationAttributes(AnnotatedElement element, String annotationName)Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.static MultiValueMap<String,Object>getAllAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.static <A extends Annotation>
Set<A>getAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType)Get all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static AnnotationAttributesgetAnnotationAttributes(AnnotatedElement element, String annotationName)已过时。As of Spring Framework 4.2, usegetMergedAnnotationAttributes(AnnotatedElement, String)instead.static AnnotationAttributesgetAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)已过时。As of Spring Framework 4.2, usegetMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)instead.static <A extends Annotation>
AgetMergedAnnotation(AnnotatedElement element, Class<A> annotationType)Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.static AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType)Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, String annotationName)Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static AnnotationAttributesgetMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.static <A extends Annotation>
Set<A>getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static <A extends Annotation>
Set<A>getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, Class<? extends Annotation> containerType)Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.static Set<String>getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType)Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationType) on the suppliedAnnotatedElement.static Set<String>getMetaAnnotationTypes(AnnotatedElement element, String annotationName)Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationName) on the suppliedAnnotatedElement.static booleanhasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType)Determine if an annotation of the specifiedannotationTypeis available on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.static booleanhasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType)Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationType.static booleanhasMetaAnnotationTypes(AnnotatedElement element, String annotationName)Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationName.static booleanisAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType)Determine if an annotation of the specifiedannotationTypeis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.static booleanisAnnotated(AnnotatedElement element, String annotationName)Determine if an annotation of the specifiedannotationNameis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.
构造器详细资料
AnnotatedElementUtils
public AnnotatedElementUtils()
方法详细资料
forAnnotations
public static AnnotatedElement forAnnotations(Annotation... annotations)
Build an adaptedAnnotatedElementfor the given annotations, typically for use with other methods onAnnotatedElementUtils.- 参数:
annotations- the annotations to expose through theAnnotatedElement- 从以下版本开始:
- 4.3
getMetaAnnotationTypes
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType)
Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationType) on the suppliedAnnotatedElement.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the annotation type on which to find meta-annotations- 返回:
- the names of all meta-annotations present on the annotation, or
nullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
getMetaAnnotationTypes(AnnotatedElement, String),hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
getMetaAnnotationTypes
public static Set<String> getMetaAnnotationTypes(AnnotatedElement element, String annotationName)
Get the fully qualified class names of all meta-annotation types present on the annotation (of the specifiedannotationName) on the suppliedAnnotatedElement.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type on which to find meta-annotations- 返回:
- the names of all meta-annotations present on the annotation, or
nullif not found - 另请参阅:
getMetaAnnotationTypes(AnnotatedElement, Class),hasMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
hasMetaAnnotationTypes
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, Class<? extends Annotation> annotationType)
Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationType.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the meta-annotation type to find- 返回:
trueif a matching meta-annotation is present- 从以下版本开始:
- 4.2.3
- 另请参阅:
getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
hasMetaAnnotationTypes
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationName)
Determine if the suppliedAnnotatedElementis annotated with a composed annotation that is meta-annotated with an annotation of the specifiedannotationName.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the meta-annotation type to find- 返回:
trueif a matching meta-annotation is present- 另请参阅:
getMetaAnnotationTypes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)
isAnnotated
public static boolean isAnnotated(AnnotatedElement element, Class<? extends Annotation> annotationType)
Determine if an annotation of the specifiedannotationTypeis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns
true, thengetMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)will return a non-null value.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the annotation type to find- 返回:
trueif a matching annotation is present- 从以下版本开始:
- 4.2.3
- 另请参阅:
hasAnnotation(AnnotatedElement, Class)
isAnnotated
public static boolean isAnnotated(AnnotatedElement element, String annotationName)
Determine if an annotation of the specifiedannotationNameis present on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns
true, thengetMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>)will return a non-null value.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to find- 返回:
trueif a matching annotation is present
getAnnotationAttributes
@Deprecated public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement element, String annotationName)
已过时。As of Spring Framework 4.2, usegetMergedAnnotationAttributes(AnnotatedElement, String)instead.
getAnnotationAttributes
@Deprecated public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
已过时。As of Spring Framework 4.2, usegetMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)instead.
getMergedAnnotationAttributes
public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType)
Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to
getMergedAnnotationAttributes(AnnotatedElement, String).- 参数:
element- the annotated elementannotationType- the annotation type to find- 返回:
- the merged
AnnotationAttributes, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),getMergedAnnotation(AnnotatedElement, Class),findMergedAnnotation(AnnotatedElement, Class)
getMergedAnnotationAttributes
public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName)
Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to
getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean), supplyingfalseforclassValuesAsStringandnestedAnnotationsAsMap.- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to find- 返回:
- the merged
AnnotationAttributes, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),findMergedAnnotation(AnnotatedElement, Class),getAllAnnotationAttributes(AnnotatedElement, String)
getMergedAnnotationAttributes
public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
Get the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and
@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to
getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationNamehas been found. As a consequence, additional annotations of the specifiedannotationNamewill be ignored.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to findclassValuesAsString- whether to convert Class references into Strings or to preserve them as Class referencesnestedAnnotationsAsMap- whether to convert nested Annotation instances intoAnnotationAttributesmaps or to preserve them as Annotation instances- 返回:
- the merged
AnnotationAttributes, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
getMergedAnnotation
public static <A extends Annotation> A getMergedAnnotation(AnnotatedElement element, Class<A> annotationType)
Get the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to
getMergedAnnotationAttributes(AnnotatedElement, Class)andAnnotationUtils.synthesizeAnnotation(Map, Class, AnnotatedElement).- 参数:
element- the annotated elementannotationType- the annotation type to find- 返回:
- the merged, synthesized
Annotation, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
getMergedAnnotationAttributes(AnnotatedElement, Class),findMergedAnnotation(AnnotatedElement, Class),AnnotationUtils.synthesizeAnnotation(Map, Class, AnnotatedElement)
getAllMergedAnnotations
public static <A extends Annotation> Set<A> getAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType)
Get all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)- 返回:
- the set of all merged, synthesized
Annotationsfound, or an empty set if none were found - 从以下版本开始:
- 4.3
- 另请参阅:
getMergedAnnotation(AnnotatedElement, Class),getAllAnnotationAttributes(AnnotatedElement, String),findAllMergedAnnotations(AnnotatedElement, Class)
getMergedRepeatableAnnotations
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)
Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.The container type that holds the repeatable annotations will be looked up via
Repeatable.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)- 返回:
- the set of all merged repeatable
Annotationsfound, or an empty set if none were found - 抛出:
IllegalArgumentException- if theelementorannotationTypeisnull, or if the container type cannot be resolved- 从以下版本开始:
- 4.3
- 另请参阅:
getMergedAnnotation(AnnotatedElement, Class),getAllMergedAnnotations(AnnotatedElement, Class),getMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
getMergedRepeatableAnnotations
public static <A extends Annotation> Set<A> getMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, Class<? extends Annotation> containerType)
Get all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)containerType- the type of the container that holds the annotations; may benullif the container type should be looked up viaRepeatable- 返回:
- the set of all merged repeatable
Annotationsfound, or an empty set if none were found - 抛出:
IllegalArgumentException- if theelementorannotationTypeisnull, or if the container type cannot be resolvedAnnotationConfigurationException- if the suppliedcontainerTypeis not a valid container annotation for the suppliedannotationType- 从以下版本开始:
- 4.3
- 另请参阅:
getMergedAnnotation(AnnotatedElement, Class),getAllMergedAnnotations(AnnotatedElement, Class)
getAllAnnotationAttributes
public static MultiValueMap<String,Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName)
Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.Note: in contrast to
getMergedAnnotationAttributes(AnnotatedElement, String), this method does not support attribute overrides.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to find- 返回:
- a
MultiValueMapkeyed by attribute name, containing the annotation attributes from all annotations found, ornullif not found - 另请参阅:
getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
getAllAnnotationAttributes
public static MultiValueMap<String,Object> getAllAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
Get the annotation attributes of all annotations of the specifiedannotationNamein the annotation hierarchy above the suppliedAnnotatedElementand store the results in aMultiValueMap.Note: in contrast to
getMergedAnnotationAttributes(AnnotatedElement, String), this method does not support attribute overrides.This method follows get semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to findclassValuesAsString- whether to convert Class references into Strings or to preserve them as Class referencesnestedAnnotationsAsMap- whether to convert nested Annotation instances intoAnnotationAttributesmaps or to preserve them as Annotation instances- 返回:
- a
MultiValueMapkeyed by attribute name, containing the annotation attributes from all annotations found, ornullif not found
hasAnnotation
public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType)
Determine if an annotation of the specifiedannotationTypeis available on the suppliedAnnotatedElementor within the annotation hierarchy above the specified element.If this method returns
true, thenfindMergedAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation>, boolean, boolean)will return a non-null value.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the annotation type to find- 返回:
trueif a matching annotation is present- 从以下版本开始:
- 4.3
- 另请参阅:
isAnnotated(AnnotatedElement, Class)
findMergedAnnotationAttributes
public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and
@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to
getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationTypehas been found. As a consequence, additional annotations of the specifiedannotationTypewill be ignored.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the annotation type to findclassValuesAsString- whether to convert Class references into Strings or to preserve them as Class referencesnestedAnnotationsAsMap- whether to convert nested Annotation instances intoAnnotationAttributesmaps or to preserve them as Annotation instances- 返回:
- the merged
AnnotationAttributes, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
findMergedAnnotationAttributes
public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap)
Find the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelementand merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy.Attributes from lower levels in the annotation hierarchy override attributes of the same name from higher levels, and
@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.In contrast to
getAllAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String), the search algorithm used by this method will stop searching the annotation hierarchy once the first annotation of the specifiedannotationNamehas been found. As a consequence, additional annotations of the specifiedannotationNamewill be ignored.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to findclassValuesAsString- whether to convert Class references into Strings or to preserve them as Class referencesnestedAnnotationsAsMap- whether to convert nested Annotation instances intoAnnotationAttributesmaps or to preserve them as Annotation instances- 返回:
- the merged
AnnotationAttributes, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
findMergedAnnotation
public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, Class<A> annotationType)
Find the first annotation of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationType- the annotation type to find- 返回:
- the merged, synthesized
Annotation, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
findAllMergedAnnotations(AnnotatedElement, Class),findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),getMergedAnnotationAttributes(AnnotatedElement, Class)
findMergedAnnotation
@Deprecated public static <A extends Annotation> A findMergedAnnotation(AnnotatedElement element, String annotationName)
已过时。As of Spring Framework 4.2.3, usefindMergedAnnotation(AnnotatedElement, Class)instead.Find the first annotation of the specifiedannotationNamewithin the annotation hierarchy above the suppliedelement, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy, and synthesize the result back into an annotation of the specifiedannotationName.@AliasForsemantics are fully supported, both within a single annotation and within the annotation hierarchy.This method delegates to
findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)(supplyingfalseforclassValuesAsStringandnestedAnnotationsAsMap) andAnnotationUtils.synthesizeAnnotation(Map, Class, AnnotatedElement).This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated elementannotationName- the fully qualified class name of the annotation type to find- 返回:
- the merged, synthesized
Annotation, ornullif not found - 从以下版本开始:
- 4.2
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean),AnnotationUtils.synthesizeAnnotation(Map, Class, AnnotatedElement)
findAllMergedAnnotations
public static <A extends Annotation> Set<A> findAllMergedAnnotations(AnnotatedElement element, Class<A> annotationType)
Find all annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)- 返回:
- the set of all merged, synthesized
Annotationsfound, or an empty set if none were found - 从以下版本开始:
- 4.3
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),getAllMergedAnnotations(AnnotatedElement, Class)
findMergedRepeatableAnnotations
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType)
Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.The container type that holds the repeatable annotations will be looked up via
Repeatable.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)- 返回:
- the set of all merged repeatable
Annotationsfound, or an empty set if none were found - 抛出:
IllegalArgumentException- if theelementorannotationTypeisnull, or if the container type cannot be resolved- 从以下版本开始:
- 4.3
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),findAllMergedAnnotations(AnnotatedElement, Class),findMergedRepeatableAnnotations(AnnotatedElement, Class, Class)
findMergedRepeatableAnnotations
public static <A extends Annotation> Set<A> findMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType, Class<? extends Annotation> containerType)
Find all repeatable annotations of the specifiedannotationTypewithin the annotation hierarchy above the suppliedelement; and for each annotation found, merge that annotation's attributes with matching attributes from annotations in lower levels of the annotation hierarchy and synthesize the results back into an annotation of the specifiedannotationType.@AliasForsemantics are fully supported, both within a single annotation and within annotation hierarchies.This method follows find semantics as described in the class-level javadoc.
- 参数:
element- the annotated element (nevernull)annotationType- the annotation type to find (nevernull)containerType- the type of the container that holds the annotations; may benullif the container type should be looked up viaRepeatable- 返回:
- the set of all merged repeatable
Annotationsfound, or an empty set if none were found - 抛出:
IllegalArgumentException- if theelementorannotationTypeisnull, or if the container type cannot be resolvedAnnotationConfigurationException- if the suppliedcontainerTypeis not a valid container annotation for the suppliedannotationType- 从以下版本开始:
- 4.3
- 另请参阅:
findMergedAnnotation(AnnotatedElement, Class),findAllMergedAnnotations(AnnotatedElement, Class)