@@ -558,6 +558,9 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
558
558
// Register exception, in case the bean was accidentally unresolvable.
559
559
onSuppressedException (ex );
560
560
}
561
+ catch (NoSuchBeanDefinitionException ex ) {
562
+ // Bean definition got removed while we were iterating -> ignore.
563
+ }
561
564
}
562
565
}
563
566
@@ -649,7 +652,7 @@ public <T> Map<String, T> getBeansOfType(
649
652
public String [] getBeanNamesForAnnotation (Class <? extends Annotation > annotationType ) {
650
653
List <String > result = new ArrayList <>();
651
654
for (String beanName : this .beanDefinitionNames ) {
652
- BeanDefinition beanDefinition = getBeanDefinition (beanName );
655
+ BeanDefinition beanDefinition = this . beanDefinitionMap . get (beanName );
653
656
if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
654
657
result .add (beanName );
655
658
}
@@ -1721,18 +1724,23 @@ private void raiseNoMatchingBeanFound(
1721
1724
*/
1722
1725
private void checkBeanNotOfRequiredType (Class <?> type , DependencyDescriptor descriptor ) {
1723
1726
for (String beanName : this .beanDefinitionNames ) {
1724
- RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1725
- Class <?> targetType = mbd .getTargetType ();
1726
- if (targetType != null && type .isAssignableFrom (targetType ) &&
1727
- isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1728
- // Probably a proxy interfering with target type match -> throw meaningful exception.
1729
- Object beanInstance = getSingleton (beanName , false );
1730
- Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1731
- beanInstance .getClass () : predictBeanType (beanName , mbd ));
1732
- if (beanType != null && !type .isAssignableFrom (beanType )) {
1733
- throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1727
+ try {
1728
+ RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1729
+ Class <?> targetType = mbd .getTargetType ();
1730
+ if (targetType != null && type .isAssignableFrom (targetType ) &&
1731
+ isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1732
+ // Probably a proxy interfering with target type match -> throw meaningful exception.
1733
+ Object beanInstance = getSingleton (beanName , false );
1734
+ Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1735
+ beanInstance .getClass () : predictBeanType (beanName , mbd ));
1736
+ if (beanType != null && !type .isAssignableFrom (beanType )) {
1737
+ throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1738
+ }
1734
1739
}
1735
1740
}
1741
+ catch (NoSuchBeanDefinitionException ex ) {
1742
+ // Bean definition got removed while we were iterating -> ignore.
1743
+ }
1736
1744
}
1737
1745
1738
1746
BeanFactory parent = getParentBeanFactory ();
0 commit comments