@ -76,7 +76,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
private final Map < String , Class < ? > > beanTypes = new HashMap < String , Class < ? > > ( ) ;
private int lastBeanDefinitionCount = 0 ;
private final Map < String , RootBeanDefinition > beanDefinitions = new HashMap < String , RootBeanDefinition > ( ) ;
private BeanTypeRegistry ( DefaultListableBeanFactory beanFactory ) {
this . beanFactory = beanFactory ;
@ -146,7 +146,7 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
public void afterSingletonsInstantiated ( ) {
// We're done at this point, free up some memory
this . beanTypes . clear ( ) ;
this . lastBeanDefinitionCount = 0 ;
this . beanDefinitions. clear ( ) ;
}
private void addBeanType ( String name ) {
@ -159,10 +159,23 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
}
private void addBeanTypeForNonAliasDefinition ( String name ) {
addBeanTypeForNonAliasDefinition ( name , getBeanDefinition ( name ) ) ;
}
private RootBeanDefinition getBeanDefinition ( String name ) {
try {
return ( RootBeanDefinition ) this . beanFactory . getMergedBeanDefinition ( name ) ;
}
catch ( BeanDefinitionStoreException ex ) {
logIgnoredError ( "unresolvable metadata in bean definition" , name , ex ) ;
return null ;
}
}
private void addBeanTypeForNonAliasDefinition ( String name ,
RootBeanDefinition beanDefinition ) {
try {
String factoryName = BeanFactory . FACTORY_BEAN_PREFIX + name ;
RootBeanDefinition beanDefinition = ( RootBeanDefinition ) this . beanFactory
. getMergedBeanDefinition ( name ) ;
if ( ! beanDefinition . isAbstract ( )
& & ! requiresEagerInit ( beanDefinition . getFactoryBeanName ( ) ) ) {
if ( this . beanFactory . isFactoryBean ( factoryName ) ) {
@ -176,15 +189,12 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
this . beanTypes . put ( name , this . beanFactory . getType ( name ) ) ;
}
}
this . beanDefinitions . put ( name , beanDefinition ) ;
}
catch ( CannotLoadBeanClassException ex ) {
// Probably contains a placeholder
logIgnoredError ( "bean class loading failure for bean" , name , ex ) ;
}
catch ( BeanDefinitionStoreException ex ) {
// Probably contains a placeholder
logIgnoredError ( "unresolvable metadata in bean definition" , name , ex ) ;
}
}
private void logIgnoredError ( String message , String name , Exception ex ) {
@ -199,15 +209,24 @@ final class BeanTypeRegistry implements SmartInitializingSingleton {
}
private void updateTypesIfNecessary ( ) {
if ( this . lastBeanDefinitionCount ! = this . beanFactory . getBeanDefinitionCount ( ) ) {
Iterator < String > names = this . beanFactory . getBeanNamesIterator ( ) ;
while ( names . hasNext ( ) ) {
String name = names . next ( ) ;
if ( ! this . beanTypes . containsKey ( name ) ) {
addBeanType ( name ) ;
Iterator < String > names = this . beanFactory . getBeanNamesIterator ( ) ;
while ( names . hasNext ( ) ) {
String name = names . next ( ) ;
if ( ! this . beanTypes . containsKey ( name ) ) {
addBeanType ( name ) ;
}
else {
if ( ! this . beanFactory . isAlias ( name )
& & ! this . beanFactory . containsSingleton ( name ) ) {
RootBeanDefinition beanDefinition = getBeanDefinition ( name ) ;
RootBeanDefinition existingDefinition = this . beanDefinitions . put ( name ,
beanDefinition ) ;
if ( existingDefinition ! = null
& & ! beanDefinition . equals ( existingDefinition ) ) {
addBeanTypeForNonAliasDefinition ( name , beanDefinition ) ;
}
}
}
this . lastBeanDefinitionCount = this . beanFactory . getBeanDefinitionCount ( ) ;
}
}