Leniently accept same singleton instance if implicitly appeared

Closes gh-34427
This commit is contained in:
Juergen Hoeller
2025-02-18 13:01:08 +01:00
parent 2576702cda
commit 94eb6006e8
2 changed files with 21 additions and 6 deletions

View File

@@ -368,8 +368,18 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
}
afterSingletonCreation(beanName);
}
if (newSingleton) {
addSingleton(beanName, singletonObject);
try {
addSingleton(beanName, singletonObject);
}
catch (IllegalStateException ex) {
// Leniently accept same instance if implicitly appeared.
Object object = this.singletonObjects.get(beanName);
if (singletonObject != object) {
throw ex;
}
}
}
}
return singletonObject;