|
72 | 72 | import org.springframework.beans.factory.config.NamedBeanHolder;
|
73 | 73 | import org.springframework.core.OrderComparator;
|
74 | 74 | import org.springframework.core.ResolvableType;
|
75 |
| -import org.springframework.core.annotation.AnnotationUtils; |
| 75 | +import org.springframework.core.annotation.MergedAnnotation; |
| 76 | +import org.springframework.core.annotation.MergedAnnotations; |
| 77 | +import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; |
76 | 78 | import org.springframework.lang.Nullable;
|
77 | 79 | import org.springframework.util.Assert;
|
78 | 80 | import org.springframework.util.ClassUtils;
|
@@ -666,22 +668,33 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an
|
666 | 668 | @Nullable
|
667 | 669 | public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
668 | 670 | throws NoSuchBeanDefinitionException {
|
| 671 | + return findMergedAnnotationOnBean(beanName, annotationType).synthesize( |
| 672 | + MergedAnnotation::isPresent).orElse(null); |
| 673 | + } |
669 | 674 |
|
670 |
| - A ann = null; |
| 675 | + private <A extends Annotation> MergedAnnotation<A> findMergedAnnotationOnBean( |
| 676 | + String beanName, Class<A> annotationType) { |
671 | 677 | Class<?> beanType = getType(beanName);
|
672 | 678 | if (beanType != null) {
|
673 |
| - ann = AnnotationUtils.findAnnotation(beanType, annotationType); |
| 679 | + MergedAnnotation<A> annotation = MergedAnnotations.from(beanType, |
| 680 | + SearchStrategy.EXHAUSTIVE).get(annotationType); |
| 681 | + if (annotation.isPresent()) { |
| 682 | + return annotation; |
| 683 | + } |
674 | 684 | }
|
675 |
| - if (ann == null && containsBeanDefinition(beanName)) { |
| 685 | + if (containsBeanDefinition(beanName)) { |
676 | 686 | BeanDefinition bd = getMergedBeanDefinition(beanName);
|
677 | 687 | if (bd instanceof AbstractBeanDefinition) {
|
678 | 688 | AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
|
679 | 689 | if (abd.hasBeanClass()) {
|
680 |
| - ann = AnnotationUtils.findAnnotation(abd.getBeanClass(), annotationType); |
| 690 | + Class<?> beanClass = abd.getBeanClass(); |
| 691 | + if (beanClass != beanType) { |
| 692 | + return MergedAnnotations.from(beanClass, SearchStrategy.EXHAUSTIVE).get(annotationType); |
| 693 | + } |
681 | 694 | }
|
682 | 695 | }
|
683 | 696 | }
|
684 |
| - return ann; |
| 697 | + return MergedAnnotation.missing(); |
685 | 698 | }
|
686 | 699 |
|
687 | 700 |
|
|
0 commit comments