@@ -454,6 +454,9 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
454
454
}
455
455
onSuppressedException (ex );
456
456
}
457
+ catch (NoSuchBeanDefinitionException ex ) {
458
+ // Bean definition got removed while we were iterating -> ignore.
459
+ }
457
460
}
458
461
}
459
462
@@ -540,7 +543,7 @@ public <T> Map<String, T> getBeansOfType(
540
543
public String [] getBeanNamesForAnnotation (Class <? extends Annotation > annotationType ) {
541
544
List <String > result = new ArrayList <>();
542
545
for (String beanName : this .beanDefinitionNames ) {
543
- BeanDefinition beanDefinition = getBeanDefinition (beanName );
546
+ BeanDefinition beanDefinition = this . beanDefinitionMap . get (beanName );
544
547
if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
545
548
result .add (beanName );
546
549
}
@@ -1511,18 +1514,23 @@ private void raiseNoMatchingBeanFound(
1511
1514
*/
1512
1515
private void checkBeanNotOfRequiredType (Class <?> type , DependencyDescriptor descriptor ) {
1513
1516
for (String beanName : this .beanDefinitionNames ) {
1514
- RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1515
- Class <?> targetType = mbd .getTargetType ();
1516
- if (targetType != null && type .isAssignableFrom (targetType ) &&
1517
- isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1518
- // Probably a proxy interfering with target type match -> throw meaningful exception.
1519
- Object beanInstance = getSingleton (beanName , false );
1520
- Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1521
- beanInstance .getClass () : predictBeanType (beanName , mbd ));
1522
- if (beanType != null && !type .isAssignableFrom (beanType )) {
1523
- throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1517
+ try {
1518
+ RootBeanDefinition mbd = getMergedLocalBeanDefinition (beanName );
1519
+ Class <?> targetType = mbd .getTargetType ();
1520
+ if (targetType != null && type .isAssignableFrom (targetType ) &&
1521
+ isAutowireCandidate (beanName , mbd , descriptor , getAutowireCandidateResolver ())) {
1522
+ // Probably a proxy interfering with target type match -> throw meaningful exception.
1523
+ Object beanInstance = getSingleton (beanName , false );
1524
+ Class <?> beanType = (beanInstance != null && beanInstance .getClass () != NullBean .class ?
1525
+ beanInstance .getClass () : predictBeanType (beanName , mbd ));
1526
+ if (beanType != null && !type .isAssignableFrom (beanType )) {
1527
+ throw new BeanNotOfRequiredTypeException (beanName , type , beanType );
1528
+ }
1524
1529
}
1525
1530
}
1531
+ catch (NoSuchBeanDefinitionException ex ) {
1532
+ // Bean definition got removed while we were iterating -> ignore.
1533
+ }
1526
1534
}
1527
1535
1528
1536
BeanFactory parent = getParentBeanFactory ();
0 commit comments