Skip to content

Commit fa95593

Browse files
committed
Merge branch '6.1.x'
# Conflicts: # spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java
2 parents 92c9b0d + fde7116 commit fa95593

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] an
179179
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
180180
for (Annotation annotation : annotationsToSearch) {
181181
Class<? extends Annotation> type = annotation.annotationType();
182+
if (isPlainJavaAnnotation(type)) {
183+
continue;
184+
}
182185
boolean checkMeta = true;
183186
boolean fallbackToMeta = false;
184187
if (isQualifier(type)) {
@@ -194,6 +197,9 @@ protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] an
194197
boolean foundMeta = false;
195198
for (Annotation metaAnn : type.getAnnotations()) {
196199
Class<? extends Annotation> metaType = metaAnn.annotationType();
200+
if (isPlainJavaAnnotation(metaType)) {
201+
continue;
202+
}
197203
if (isQualifier(metaType)) {
198204
qualifierFound = true;
199205
foundMeta = true;
@@ -215,7 +221,17 @@ protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] an
215221
}
216222

217223
/**
218-
* Checks whether the given annotation type is a recognized qualifier type.
224+
* Check whether the given annotation type is a plain "java." annotation,
225+
* typically from {@code java.lang.annotation}.
226+
* <p>Aligned with
227+
* {@code org.springframework.core.annotation.AnnotationsScanner#hasPlainJavaAnnotationsOnly}.
228+
*/
229+
private boolean isPlainJavaAnnotation(Class<? extends Annotation> annotationType) {
230+
return annotationType.getName().startsWith("java.");
231+
}
232+
233+
/**
234+
* Check whether the given annotation type is a recognized qualifier type.
219235
*/
220236
protected boolean isQualifier(Class<? extends Annotation> annotationType) {
221237
for (Class<? extends Annotation> qualifierType : this.qualifierTypes) {

spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,25 @@ private static <C, R> R processClass(C context, Class<?> source, SearchStrategy
103103

104104
return switch (searchStrategy) {
105105
case DIRECT -> processElement(context, source, processor);
106-
case INHERITED_ANNOTATIONS -> processClassInheritedAnnotations(context, source, searchStrategy, processor);
106+
case INHERITED_ANNOTATIONS -> processClassInheritedAnnotations(context, source, processor);
107107
case SUPERCLASS -> processClassHierarchy(context, source, processor, false, Search.never);
108108
case TYPE_HIERARCHY -> processClassHierarchy(context, source, processor, true, searchEnclosingClass);
109109
};
110110
}
111111

112112
@Nullable
113113
private static <C, R> R processClassInheritedAnnotations(C context, Class<?> source,
114-
SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor) {
114+
AnnotationsProcessor<C, R> processor) {
115115

116116
try {
117-
if (isWithoutHierarchy(source, searchStrategy, Search.never)) {
117+
if (isWithoutHierarchy(source, Search.never)) {
118118
return processElement(context, source, processor);
119119
}
120120
Annotation[] relevant = null;
121121
int remaining = Integer.MAX_VALUE;
122122
int aggregateIndex = 0;
123123
Class<?> root = source;
124-
while (source != null && source != Object.class && remaining > 0 &&
125-
!hasPlainJavaAnnotationsOnly(source)) {
124+
while (source != null && source != Object.class && remaining > 0 && !hasPlainJavaAnnotationsOnly(source)) {
126125
R result = processor.doWithAggregate(context, aggregateIndex);
127126
if (result != null) {
128127
return result;
@@ -483,7 +482,7 @@ static boolean isKnownEmpty(AnnotatedElement source, SearchStrategy searchStrate
483482
if (hasPlainJavaAnnotationsOnly(source)) {
484483
return true;
485484
}
486-
if (searchStrategy == SearchStrategy.DIRECT || isWithoutHierarchy(source, searchStrategy, searchEnclosingClass)) {
485+
if (searchStrategy == SearchStrategy.DIRECT || isWithoutHierarchy(source, searchEnclosingClass)) {
487486
if (source instanceof Method method && method.isBridge()) {
488487
return false;
489488
}
@@ -508,9 +507,7 @@ static boolean hasPlainJavaAnnotationsOnly(Class<?> type) {
508507
return (type.getName().startsWith("java.") || type == Ordered.class);
509508
}
510509

511-
private static boolean isWithoutHierarchy(AnnotatedElement source, SearchStrategy searchStrategy,
512-
Predicate<Class<?>> searchEnclosingClass) {
513-
510+
private static boolean isWithoutHierarchy(AnnotatedElement source, Predicate<Class<?>> searchEnclosingClass) {
514511
if (source == Object.class) {
515512
return true;
516513
}
@@ -522,7 +519,7 @@ private static boolean isWithoutHierarchy(AnnotatedElement source, SearchStrateg
522519
}
523520
if (source instanceof Method sourceMethod) {
524521
return (Modifier.isPrivate(sourceMethod.getModifiers()) ||
525-
isWithoutHierarchy(sourceMethod.getDeclaringClass(), searchStrategy, searchEnclosingClass));
522+
isWithoutHierarchy(sourceMethod.getDeclaringClass(), searchEnclosingClass));
526523
}
527524
return true;
528525
}

0 commit comments

Comments
 (0)