From 14fef198f063637d41995db662eface0478e131e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 2 Nov 2014 20:15:36 +0100 Subject: [PATCH] Explicitly clear manually registered singleton names after destroySingletons call As indicated by our recent Spring Integration test failure, autowiring attempts after context closing did not fail before. After the introduction of the separately managed manualSingletonNames set, the algorithm could run into a situation where a singleton name is still in the manualSingletonNames set but not in the singletonObjects map anymore. As a remedy, destroySingletons needs to explicitly clear the manualSingletonNames set in order to remove references to non-disposable singleton beans as well (which are otherwise left in the set since individual destroySingleton calls only come in for disposable beans with destroy methods). Issue: SPR-12404 --- .../beans/factory/support/DefaultListableBeanFactory.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index e93cdd37cb..0a01ba17de 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -909,6 +909,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto clearByTypeCache(); } + @Override + public void destroySingletons() { + super.destroySingletons(); + this.manualSingletonNames.clear(); + clearByTypeCache(); + } + /** * Remove any assumptions about by-type mappings. */