Skip to content

Commit 933bbf2

Browse files
committed
AbstractBeanFactory.markBeanAsCreated() reliably clears merged bean definition only once
Issue: SPR-14269 (cherry picked from commit 9064d38)
1 parent 1d0c305 commit 933bbf2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1498,11 +1498,14 @@ else if (mbd.isLazyInit()) {
14981498
*/
14991499
protected void markBeanAsCreated(String beanName) {
15001500
if (!this.alreadyCreated.contains(beanName)) {
1501-
this.alreadyCreated.add(beanName);
1502-
1503-
// Let the bean definition get re-merged now that we're actually creating
1504-
// the bean... just in case some of its metadata changed in the meantime.
1505-
clearMergedBeanDefinition(beanName);
1501+
synchronized (this.mergedBeanDefinitions) {
1502+
if (!this.alreadyCreated.contains(beanName)) {
1503+
// Let the bean definition get re-merged now that we're actually creating
1504+
// the bean... just in case some of its metadata changed in the meantime.
1505+
clearMergedBeanDefinition(beanName);
1506+
this.alreadyCreated.add(beanName);
1507+
}
1508+
}
15061509
}
15071510
}
15081511

@@ -1511,7 +1514,9 @@ protected void markBeanAsCreated(String beanName) {
15111514
* @param beanName the name of the bean
15121515
*/
15131516
protected void cleanupAfterBeanCreationFailure(String beanName) {
1514-
this.alreadyCreated.remove(beanName);
1517+
synchronized (this.mergedBeanDefinitions) {
1518+
this.alreadyCreated.remove(beanName);
1519+
}
15151520
}
15161521

15171522
/**

0 commit comments

Comments
 (0)