Skip to content

Commit dd9b674

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 2b9cea6 commit dd9b674

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-2021 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.
@@ -402,8 +402,8 @@ else if (field.isAnnotationPresent(Resource.class)) {
402402
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
403403
return;
404404
}
405-
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
406-
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
405+
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
406+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
407407
if (Modifier.isStatic(method.getModifiers())) {
408408
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
409409
}
@@ -413,7 +413,9 @@ else if (field.isAnnotationPresent(Resource.class)) {
413413
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
414414
currElements.add(new WebServiceRefElement(method, bridgedMethod, pd));
415415
}
416-
else if (ejbClass != null && bridgedMethod.isAnnotationPresent(ejbClass)) {
416+
}
417+
else if (ejbClass != null && bridgedMethod.isAnnotationPresent(ejbClass)) {
418+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
417419
if (Modifier.isStatic(method.getModifiers())) {
418420
throw new IllegalStateException("@EJB annotation is not supported on static methods");
419421
}
@@ -423,7 +425,9 @@ else if (ejbClass != null && bridgedMethod.isAnnotationPresent(ejbClass)) {
423425
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
424426
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
425427
}
426-
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
428+
}
429+
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
430+
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
427431
if (Modifier.isStatic(method.getModifiers())) {
428432
throw new IllegalStateException("@Resource annotation is not supported on static methods");
429433
}

0 commit comments

Comments
 (0)