Skip to content

Commit 9912a52

Browse files
committed
Avoid getMostSpecificMethod resolution for non-annotated methods
This is aligned with AutowiredAnnotationBeanPostProcessor now. Closes gh-31967
1 parent 419e34e commit 9912a52

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -456,8 +456,8 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp
456456
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
457457
return;
458458
}
459-
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
460-
if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) {
459+
if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) {
460+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
461461
if (Modifier.isStatic(method.getModifiers())) {
462462
throw new IllegalStateException("@EJB annotation is not supported on static methods");
463463
}
@@ -467,7 +467,9 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp
467467
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
468468
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
469469
}
470-
else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) {
470+
}
471+
else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) {
472+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
471473
if (Modifier.isStatic(method.getModifiers())) {
472474
throw new IllegalStateException("@Resource annotation is not supported on static methods");
473475
}
@@ -480,7 +482,9 @@ else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakart
480482
currElements.add(new ResourceElement(method, bridgedMethod, pd));
481483
}
482484
}
483-
else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) {
485+
}
486+
else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) {
487+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
484488
if (Modifier.isStatic(method.getModifiers())) {
485489
throw new IllegalStateException("@Resource annotation is not supported on static methods");
486490
}

0 commit comments

Comments
 (0)