Skip to content

Commit 75b5230

Browse files
philwebbjhoeller
authored andcommitted
Migrate CommonAnnotationBeanPostProcessor to MergedAnnotations
Closes gh-22585
1 parent 50c2577 commit 75b5230

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.springframework.core.MethodParameter;
6666
import org.springframework.core.Ordered;
6767
import org.springframework.core.annotation.AnnotationUtils;
68+
import org.springframework.core.annotation.MergedAnnotations;
6869
import org.springframework.jndi.support.SimpleJndiBeanFactory;
6970
import org.springframework.lang.Nullable;
7071
import org.springframework.util.Assert;
@@ -379,19 +380,20 @@ private InjectionMetadata buildResourceMetadata(final Class<?> clazz) {
379380
final List<InjectionMetadata.InjectedElement> currElements = new ArrayList<>();
380381

381382
ReflectionUtils.doWithLocalFields(targetClass, field -> {
382-
if (webServiceRefClass != null && field.isAnnotationPresent(webServiceRefClass)) {
383+
MergedAnnotations annotations = MergedAnnotations.from(field);
384+
if (webServiceRefClass != null && annotations.isDirectlyPresent(webServiceRefClass)) {
383385
if (Modifier.isStatic(field.getModifiers())) {
384386
throw new IllegalStateException("@WebServiceRef annotation is not supported on static fields");
385387
}
386388
currElements.add(new WebServiceRefElement(field, field, null));
387389
}
388-
else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
390+
else if (ejbRefClass != null && annotations.isDirectlyPresent(ejbRefClass)) {
389391
if (Modifier.isStatic(field.getModifiers())) {
390392
throw new IllegalStateException("@EJB annotation is not supported on static fields");
391393
}
392394
currElements.add(new EjbRefElement(field, field, null));
393395
}
394-
else if (field.isAnnotationPresent(Resource.class)) {
396+
else if (annotations.isDirectlyPresent(Resource.class)) {
395397
if (Modifier.isStatic(field.getModifiers())) {
396398
throw new IllegalStateException("@Resource annotation is not supported on static fields");
397399
}
@@ -407,7 +409,8 @@ else if (field.isAnnotationPresent(Resource.class)) {
407409
return;
408410
}
409411
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
410-
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
412+
MergedAnnotations annotations = MergedAnnotations.from(bridgedMethod);
413+
if (webServiceRefClass != null && annotations.isDirectlyPresent(webServiceRefClass)) {
411414
if (Modifier.isStatic(method.getModifiers())) {
412415
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
413416
}
@@ -417,7 +420,7 @@ else if (field.isAnnotationPresent(Resource.class)) {
417420
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
418421
currElements.add(new WebServiceRefElement(method, bridgedMethod, pd));
419422
}
420-
else if (ejbRefClass != null && bridgedMethod.isAnnotationPresent(ejbRefClass)) {
423+
else if (ejbRefClass != null && annotations.isDirectlyPresent(ejbRefClass)) {
421424
if (Modifier.isStatic(method.getModifiers())) {
422425
throw new IllegalStateException("@EJB annotation is not supported on static methods");
423426
}
@@ -427,7 +430,7 @@ else if (ejbRefClass != null && bridgedMethod.isAnnotationPresent(ejbRefClass))
427430
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
428431
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
429432
}
430-
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
433+
else if (annotations.isDirectlyPresent(Resource.class)) {
431434
if (Modifier.isStatic(method.getModifiers())) {
432435
throw new IllegalStateException("@Resource annotation is not supported on static methods");
433436
}

0 commit comments

Comments
 (0)