diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 3061648a25e..f09f09709cc 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -278,19 +278,19 @@ public abstract class AnnotationUtils { Set visited) { Assert.notNull(clazz, "Class must not be null"); - A annotation = clazz.getDeclaredAnnotation(annotationType); - if (annotation != null) { - return annotation; + if (isAnnotationDeclaredLocally(annotationType, clazz)) { + return clazz.getAnnotation(annotationType); } for (Class ifc : clazz.getInterfaces()) { - annotation = findAnnotation(ifc, annotationType, visited); + A annotation = findAnnotation(ifc, annotationType, visited); if (annotation != null) { return annotation; } } for (Annotation ann : clazz.getDeclaredAnnotations()) { if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) { - annotation = findAnnotation(ann.annotationType(), annotationType, visited); + A annotation = findAnnotation(ann.annotationType(), annotationType, + visited); if (annotation != null) { return annotation; }