From d41048528f29f41ab17fbe785cade859e690e4f2 Mon Sep 17 00:00:00 2001
From: Juergen Hoeller <juergen.hoeller@broadcom.com>
Date: Mon, 3 Jun 2024 12:45:11 +0200
Subject: [PATCH] Avoid NoSuchMethodException for annotation attribute checks

Closes gh-32921

(cherry picked from commit b08883b65c19cbed6e7a93990194977f5af73e0a)
---
 .../core/annotation/AnnotationUtils.java             | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

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 986f2c4bd9b1..0ccece66bf66 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
@@ -1052,16 +1052,16 @@ public static Object getValue(@Nullable Annotation annotation, @Nullable String
 			return null;
 		}
 		try {
-			Method method = annotation.annotationType().getDeclaredMethod(attributeName);
-			return invokeAnnotationMethod(method, annotation);
-		}
-		catch (NoSuchMethodException ex) {
-			return null;
+			for (Method method : annotation.annotationType().getDeclaredMethods()) {
+				if (method.getName().equals(attributeName) && method.getParameterCount() == 0) {
+					return invokeAnnotationMethod(method, annotation);
+				}
+			}
 		}
 		catch (Throwable ex) {
 			handleValueRetrievalFailure(annotation, ex);
-			return null;
 		}
+		return null;
 	}
 
 	/**