diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java index cf552f996e..47d5ad1c8d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java @@ -180,6 +180,9 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa SimpleTypeConverter typeConverter = new SimpleTypeConverter(); for (Annotation annotation : annotationsToSearch) { Class extends Annotation> type = annotation.annotationType(); + if (isPlainJavaAnnotation(type)) { + continue; + } boolean checkMeta = true; boolean fallbackToMeta = false; if (isQualifier(type)) { @@ -194,6 +197,9 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa boolean foundMeta = false; for (Annotation metaAnn : type.getAnnotations()) { Class extends Annotation> metaType = metaAnn.annotationType(); + if (isPlainJavaAnnotation(metaType)) { + continue; + } if (isQualifier(metaType)) { foundMeta = true; // Only accept fallback match if @Qualifier annotation has a value... @@ -213,7 +219,17 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa } /** - * Checks whether the given annotation type is a recognized qualifier type. + * Check whether the given annotation type is a plain "java." annotation, + * typically from {@code java.lang.annotation}. + *
Aligned with
+ * {@code org.springframework.core.annotation.AnnotationsScanner#hasPlainJavaAnnotationsOnly}.
+ */
+ private boolean isPlainJavaAnnotation(Class extends Annotation> annotationType) {
+ return annotationType.getName().startsWith("java.");
+ }
+
+ /**
+ * Check whether the given annotation type is a recognized qualifier type.
*/
protected boolean isQualifier(Class extends Annotation> annotationType) {
for (Class extends Annotation> qualifierType : this.qualifierTypes) {
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java
index 5bd7168f96..a3d08f369b 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java
@@ -103,7 +103,7 @@ abstract class AnnotationsScanner {
return switch (searchStrategy) {
case DIRECT -> processElement(context, source, processor);
- case INHERITED_ANNOTATIONS -> processClassInheritedAnnotations(context, source, searchStrategy, processor);
+ case INHERITED_ANNOTATIONS -> processClassInheritedAnnotations(context, source, processor);
case SUPERCLASS -> processClassHierarchy(context, source, processor, false, Search.never);
case TYPE_HIERARCHY -> processClassHierarchy(context, source, processor, true, searchEnclosingClass);
};
@@ -111,18 +111,17 @@ abstract class AnnotationsScanner {
@Nullable
private static