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:
Sam Brannen
2026-02-11 17:33:15 +01:00
parent 0d4737aeec
commit 282fee5c95
2 changed files with 142 additions and 2 deletions
@@ -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;
}