mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Consistently find @Lazy as a meta-annotation at arbitrary depths
Prior to this commit, AnnotationConfigUtils looked up @Lazy as a meta-annotation at arbitrary depths (e.g., when used as a meta-meta-annotation); however, ContextAnnotationAutowireCandidateResolver only found @Lazy as a "directly present" meta-annotation. For consistency, this commit revises ContextAnnotationAutowireCandidateResolver so that it also finds @Lazy as a meta-annotation at arbitrary depths. Closes gh-36306
This commit is contained in:
+8
-2
@@ -44,6 +44,7 @@ import org.springframework.core.annotation.AnnotationUtils;
|
||||
* driven by the {@link Lazy} annotation in the {@code context.annotation} package.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotationAutowireCandidateResolver {
|
||||
@@ -60,7 +61,12 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
|
||||
|
||||
protected boolean isLazy(DependencyDescriptor descriptor) {
|
||||
for (Annotation ann : descriptor.getAnnotations()) {
|
||||
Lazy lazy = AnnotationUtils.getAnnotation(ann, Lazy.class);
|
||||
// Directly present?
|
||||
if (ann instanceof Lazy lazy && lazy.value()) {
|
||||
return true;
|
||||
}
|
||||
// Meta-present?
|
||||
Lazy lazy = AnnotationUtils.findAnnotation(ann.annotationType(), Lazy.class);
|
||||
if (lazy != null && lazy.value()) {
|
||||
return true;
|
||||
}
|
||||
@@ -69,7 +75,7 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
|
||||
if (methodParam != null) {
|
||||
Method method = methodParam.getMethod();
|
||||
if (method == null || void.class == method.getReturnType()) {
|
||||
Lazy lazy = AnnotationUtils.getAnnotation(methodParam.getAnnotatedElement(), Lazy.class);
|
||||
Lazy lazy = AnnotationUtils.findAnnotation(methodParam.getAnnotatedElement(), Lazy.class);
|
||||
if (lazy != null && lazy.value()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user