refined addApplicationListener to work any time during the refresh phase

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2910 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-02-03 23:09:42 +00:00
parent 6325a81b7d
commit 0ce0de3eab
1 changed files with 7 additions and 2 deletions

View File

@ -365,8 +365,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
}
public void addApplicationListener(ApplicationListener listener) {
if (isActive()) {
addListener(listener);
if (this.applicationEventMulticaster != null) {
this.applicationEventMulticaster.addApplicationListener(listener);
}
else {
this.applicationListeners.add(listener);
@ -838,8 +838,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
/**
* Subclasses can invoke this method to register a listener.
* Any beans in the context that are listeners are automatically added.
* <p>Note: This method only works within an active application context,
* i.e. when an ApplicationEventMulticaster is already available. Generally
* prefer the use of {@link #addApplicationListener} which is more flexible.
* @param listener the listener to register
* @deprecated as of Spring 3.0, in favor of {@link #addApplicationListener}
*/
@Deprecated
protected void addListener(ApplicationListener listener) {
getApplicationEventMulticaster().addApplicationListener(listener);
}