From 933bbf2de90c720e6ada08089c3401317230d3b0 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 31 May 2016 11:05:29 +0200 Subject: [PATCH] AbstractBeanFactory.markBeanAsCreated() reliably clears merged bean definition only once Issue: SPR-14269 (cherry picked from commit 9064d38) --- .../factory/support/AbstractBeanFactory.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index e33f085ec77..80e91528cfa 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1498,11 +1498,14 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp */ protected void markBeanAsCreated(String beanName) { if (!this.alreadyCreated.contains(beanName)) { - this.alreadyCreated.add(beanName); - - // Let the bean definition get re-merged now that we're actually creating - // the bean... just in case some of its metadata changed in the meantime. - clearMergedBeanDefinition(beanName); + synchronized (this.mergedBeanDefinitions) { + if (!this.alreadyCreated.contains(beanName)) { + // Let the bean definition get re-merged now that we're actually creating + // the bean... just in case some of its metadata changed in the meantime. + clearMergedBeanDefinition(beanName); + this.alreadyCreated.add(beanName); + } + } } } @@ -1511,7 +1514,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param beanName the name of the bean */ protected void cleanupAfterBeanCreationFailure(String beanName) { - this.alreadyCreated.remove(beanName); + synchronized (this.mergedBeanDefinitions) { + this.alreadyCreated.remove(beanName); + } } /**