Reset ApplicationEventMulticaster/MessageSource/LifecycleProcessor on close

Closes gh-21988
Closes gh-31397
This commit is contained in:
Juergen Hoeller
2023-10-10 18:10:52 +02:00
parent a6c27652b8
commit 2754da1742
3 changed files with 44 additions and 13 deletions

View File

@@ -135,6 +135,15 @@ import org.springframework.util.ReflectionUtils;
public abstract class AbstractApplicationContext extends DefaultResourceLoader
implements ConfigurableApplicationContext {
/**
* Name of the LifecycleProcessor bean in the factory.
* If none is supplied, a DefaultLifecycleProcessor is used.
* @since 3.0
* @see org.springframework.context.LifecycleProcessor
* @see org.springframework.context.support.DefaultLifecycleProcessor
*/
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
/**
* Name of the MessageSource bean in the factory.
* If none is supplied, message resolution is delegated to the parent.
@@ -142,14 +151,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
*/
public static final String MESSAGE_SOURCE_BEAN_NAME = "messageSource";
/**
* Name of the LifecycleProcessor bean in the factory.
* If none is supplied, a DefaultLifecycleProcessor is used.
* @see org.springframework.context.LifecycleProcessor
* @see org.springframework.context.support.DefaultLifecycleProcessor
*/
public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";
/**
* Name of the ApplicationEventMulticaster bean in the factory.
* If none is supplied, a default SimpleApplicationEventMulticaster is used.
@@ -433,8 +434,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
if (this.earlyApplicationEvents != null) {
this.earlyApplicationEvents.add(applicationEvent);
}
else {
getApplicationEventMulticaster().multicastEvent(applicationEvent, eventType);
else if (this.applicationEventMulticaster != null) {
this.applicationEventMulticaster.multicastEvent(applicationEvent, eventType);
}
// Publish event via parent context as well...
@@ -1093,6 +1094,11 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
this.applicationListeners.addAll(this.earlyApplicationListeners);
}
// Reset internal delegates.
this.applicationEventMulticaster = null;
this.messageSource = null;
this.lifecycleProcessor = null;
// Switch to inactive.
this.active.set(false);
}