Skip to content

Commit bad0101

Browse files
committed
Avoid getMostSpecificMethod resolution for non-annotated methods
This is aligned with AutowiredAnnotationBeanPostProcessor now. Closes gh-31967 (cherry picked from commit 9912a52)
1 parent 867a199 commit bad0101

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.
@@ -387,8 +387,8 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp
387387
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
388388
return;
389389
}
390-
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
391-
if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) {
390+
if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) {
391+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
392392
if (Modifier.isStatic(method.getModifiers())) {
393393
throw new IllegalStateException("@EJB annotation is not supported on static methods");
394394
}
@@ -398,7 +398,9 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp
398398
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
399399
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
400400
}
401-
else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) {
401+
}
402+
else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) {
403+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
402404
if (Modifier.isStatic(method.getModifiers())) {
403405
throw new IllegalStateException("@Resource annotation is not supported on static methods");
404406
}
@@ -411,7 +413,9 @@ else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakart
411413
currElements.add(new ResourceElement(method, bridgedMethod, pd));
412414
}
413415
}
414-
else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) {
416+
}
417+
else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) {
418+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
415419
if (Modifier.isStatic(method.getModifiers())) {
416420
throw new IllegalStateException("@Resource annotation is not supported on static methods");
417421
}

0 commit comments

Comments
 (0)