Skip to content

Commit abbe61b

Browse files
committed
Consistent internal use of getMergedLocalBeanDefinition
1 parent 0babc1f commit abbe61b

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,6 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an
656656
return result;
657657
}
658658

659-
/**
660-
* Find a {@link Annotation} of {@code annotationType} on the specified
661-
* bean, traversing its interfaces and super classes if no annotation can be
662-
* found on the given class itself, as well as checking its raw bean class
663-
* if not found on the exposed bean reference (e.g. in case of a proxy).
664-
*/
665659
@Override
666660
@Nullable
667661
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
@@ -673,14 +667,12 @@ public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> a
673667
ann = AnnotationUtils.findAnnotation(beanType, annotationType);
674668
}
675669
if (ann == null && containsBeanDefinition(beanName)) {
676-
BeanDefinition bd = getMergedBeanDefinition(beanName);
677-
if (bd instanceof AbstractBeanDefinition) {
678-
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
679-
if (abd.hasBeanClass()) {
680-
Class<?> beanClass = abd.getBeanClass();
681-
if (beanClass != beanType) {
682-
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
683-
}
670+
// Check raw bean class, e.g. in case of a proxy.
671+
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
672+
if (bd.hasBeanClass()) {
673+
Class<?> beanClass = bd.getBeanClass();
674+
if (beanClass != beanType) {
675+
ann = AnnotationUtils.findAnnotation(beanClass, annotationType);
684676
}
685677
}
686678
}
@@ -1975,10 +1967,11 @@ public FactoryAwareOrderSourceProvider(Map<Object, String> instancesToBeanNames)
19751967
@Override
19761968
@Nullable
19771969
public Object getOrderSource(Object obj) {
1978-
RootBeanDefinition beanDefinition = getRootBeanDefinition(this.instancesToBeanNames.get(obj));
1979-
if (beanDefinition == null) {
1970+
String beanName = this.instancesToBeanNames.get(obj);
1971+
if (beanName == null || !containsBeanDefinition(beanName)) {
19801972
return null;
19811973
}
1974+
RootBeanDefinition beanDefinition = getMergedLocalBeanDefinition(beanName);
19821975
List<Object> sources = new ArrayList<>(2);
19831976
Method factoryMethod = beanDefinition.getResolvedFactoryMethod();
19841977
if (factoryMethod != null) {
@@ -1990,17 +1983,6 @@ public Object getOrderSource(Object obj) {
19901983
}
19911984
return sources.toArray();
19921985
}
1993-
1994-
@Nullable
1995-
private RootBeanDefinition getRootBeanDefinition(@Nullable String beanName) {
1996-
if (beanName != null && containsBeanDefinition(beanName)) {
1997-
BeanDefinition bd = getMergedBeanDefinition(beanName);
1998-
if (bd instanceof RootBeanDefinition) {
1999-
return (RootBeanDefinition) bd;
2000-
}
2001-
}
2002-
return null;
2003-
}
20041986
}
20051987

20061988
}

0 commit comments

Comments
 (0)