Skip to content

Commit

Permalink
DefaultListableBeanFactory allows for init methods to register furthe…
Browse files Browse the repository at this point in the history
…r bean definitions (again; SPR-7757)
  • Loading branch information
jhoeller committed Jul 27, 2011
1 parent 18540de commit 79aa661
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public boolean isConfigurationFrozen() {
}

/**
* Considers all beans as eligible for metdata caching
* Considers all beans as eligible for metadata caching
* if the factory's configuration has been marked as frozen.
* @see #freezeConfiguration()
*/
Expand All @@ -556,9 +556,11 @@ public void preInstantiateSingletons() throws BeansException {
if (this.logger.isInfoEnabled()) {
this.logger.info("Pre-instantiating singletons in " + this);
}

synchronized (this.beanDefinitionMap) {
for (String beanName : this.beanDefinitionNames) {
// Iterate over a copy to allow for init methods which in turn register new bean definitions.
// While this may not be part of the regular factory bootstrap, it does otherwise work fine.
List<String> beanNames = new ArrayList<String>(this.beanDefinitionNames);
for (String beanName : beanNames) {
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
if (isFactoryBean(beanName)) {
Expand All @@ -572,7 +574,8 @@ public Boolean run() {
}, getAccessControlContext());
}
else {
isEagerInit = factory instanceof SmartFactoryBean && ((SmartFactoryBean) factory).isEagerInit();
isEagerInit = (factory instanceof SmartFactoryBean &&
((SmartFactoryBean) factory).isEagerInit());
}
if (isEagerInit) {
getBean(beanName);
Expand Down Expand Up @@ -666,8 +669,7 @@ protected void resetBeanDefinition(String beanName) {
destroySingleton(beanName);
}

// Reset all bean definitions that have the given bean as parent
// (recursively).
// Reset all bean definitions that have the given bean as parent (recursively).
for (String bdName : this.beanDefinitionNames) {
if (!beanName.equals(bdName)) {
BeanDefinition bd = this.beanDefinitionMap.get(bdName);
Expand Down

0 comments on commit 79aa661

Please sign in to comment.