@@ -550,6 +550,9 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
550
550
}
551
551
onSuppressedException (ex );
552
552
}
553
+ catch (NoSuchBeanDefinitionException ex ) {
554
+ // Bean definition got removed while we were iterating -> ignore.
555
+ }
553
556
}
554
557
}
555
558
@@ -638,7 +641,7 @@ public <T> Map<String, T> getBeansOfType(
638
641
public String [] getBeanNamesForAnnotation (Class <? extends Annotation > annotationType ) {
639
642
List <String > result = new ArrayList <>();
640
643
for (String beanName : this .beanDefinitionNames ) {
641
- BeanDefinition beanDefinition = getBeanDefinition (beanName );
644
+ BeanDefinition beanDefinition = this . beanDefinitionMap . get (beanName );
642
645
if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
643
646
result .add (beanName );
644
647
}
@@ -1684,18 +1687,23 @@ private void raiseNoMatchingBeanFound(
1684
1687
*/
1685
1688
private void checkBeanNotOfRequiredType (Class <?> type , DependencyDescriptor descriptor ) {
1686
1689
for (String beanName : this .beanDefinitionNames ) {
1687
- RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1688
- Class <?> targetType = mbd .getTargetType ();
1689
- if (targetType != null && type .isAssignableFrom (targetType ) &&
1690
- isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1691
- // Probably a proxy interfering with target type match -> throw meaningful exception.
1692
- Object beanInstance = getSingleton (beanName , false );
1693
- Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1694
- beanInstance .getClass () : predictBeanType (beanName , mbd ));
1695
- if (beanType != null && !type .isAssignableFrom (beanType )) {
1696
- throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1690
+ try {
1691
+ RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1692
+ Class <?> targetType = mbd .getTargetType ();
1693
+ if (targetType != null && type .isAssignableFrom (targetType ) &&
1694
+ isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1695
+ // Probably a proxy interfering with target type match -> throw meaningful exception.
1696
+ Object beanInstance = getSingleton (beanName , false );
1697
+ Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1698
+ beanInstance .getClass () : predictBeanType (beanName , mbd ));
1699
+ if (beanType != null && !type .isAssignableFrom (beanType )) {
1700
+ throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1701
+ }
1697
1702
}
1698
1703
}
1704
+ catch (NoSuchBeanDefinitionException ex ) {
1705
+ // Bean definition got removed while we were iterating -> ignore.
1706
+ }
1699
1707
}
1700
1708
1701
1709
BeanFactory parent = getParentBeanFactory ();
0 commit comments