@@ -558,6 +558,9 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
558558 // Register exception, in case the bean was accidentally unresolvable.
559559 onSuppressedException (ex );
560560 }
561+ catch (NoSuchBeanDefinitionException ex ) {
562+ // Bean definition got removed while we were iterating -> ignore.
563+ }
561564 }
562565 }
563566
@@ -649,7 +652,7 @@ public <T> Map<String, T> getBeansOfType(
649652 public String [] getBeanNamesForAnnotation (Class <? extends Annotation > annotationType ) {
650653 List <String > result = new ArrayList <>();
651654 for (String beanName : this .beanDefinitionNames ) {
652- BeanDefinition beanDefinition = getBeanDefinition (beanName );
655+ BeanDefinition beanDefinition = this . beanDefinitionMap . get (beanName );
653656 if (!beanDefinition .isAbstract () && findAnnotationOnBean (beanName , annotationType ) != null ) {
654657 result .add (beanName );
655658 }
@@ -1721,18 +1724,23 @@ private void raiseNoMatchingBeanFound(
17211724 */
17221725 private void checkBeanNotOfRequiredType (Class <?> type , DependencyDescriptor descriptor ) {
17231726 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+ }
17341739 }
17351740 }
1741+ catch (NoSuchBeanDefinitionException ex ) {
1742+ // Bean definition got removed while we were iterating -> ignore.
1743+ }
17361744 }
17371745
17381746 BeanFactory parent = getParentBeanFactory ();
0 commit comments