diff --git a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index 7f1cebd0d6b7..e8de3b323d5b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -456,8 +456,8 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) { return; } - if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { - if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) { + if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) { + if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException("@EJB annotation is not supported on static methods"); } @@ -467,7 +467,9 @@ else if (javaxResourceType != null && field.isAnnotationPresent(javaxResourceTyp PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); currElements.add(new EjbRefElement(method, bridgedMethod, pd)); } - else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) { + } + else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) { + if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException("@Resource annotation is not supported on static methods"); } @@ -480,7 +482,9 @@ else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakart currElements.add(new ResourceElement(method, bridgedMethod, pd)); } } - else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) { + } + else if (javaxResourceType != null && bridgedMethod.isAnnotationPresent(javaxResourceType)) { + if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (Modifier.isStatic(method.getModifiers())) { throw new IllegalStateException("@Resource annotation is not supported on static methods"); }