The StandardAnnotationMetadata class in Spring Framework 4.0.2 returns false for isAnnotated when a class is not directly annotated with an annotation (even if the annotation is present on a superclass). Furthermore, getAnnotationAttributes and getAllAnnotationAttributes return null when querying for the same annotation.
The fix for #16100 changed this logic and is causing problems with Spring Boot conditions. Specifically, @Conditional annotations were never previously considered on super classes (see #15466).
Don't detect annotations on superclass in StAnMeta
Changes introduced in conjunction with issue #16100 altered the
behavior of StandardAnnotationMetadata such that annotations could be
detected on superclasses, specifically in the case where the
AnnotatedElementUtils.getAllAnnotationAttributes() method is invoked to
obtain multiple annotations of the same type (on the lowest level in the
class hierarchy), as is the case for @Profile and @Conditional.
This commit partially reverts these changes as follows:
All methods in AnnotatedElementUtils now set the
traverseClassHierarchy to false, thereby effectively reverting the
changes made in commit 1d30bf8.
Note, however, that the changes made to AnnotationUtils remain in
Introduced tests in AnnotationMetadataTests that verify behavior
present in Spring Framework 4.0.2 and earlier.
Updated tests in AnnotatedElementUtilsTests so that they pass against
the reverted changes (i.e., align with the behavior present in Spring
Framework 4.0.2 and earlier).
Refined Javadoc in AnnotationMetadata with regard to annotations
being "present" vs. "defined".