提交 ce6f14bd 编写于 作者: J Juergen Hoeller

refined addApplicationListener to work any time during the refresh phase

上级 d96a6914
...@@ -365,8 +365,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader ...@@ -365,8 +365,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
} }
public void addApplicationListener(ApplicationListener listener) { public void addApplicationListener(ApplicationListener listener) {
if (isActive()) { if (this.applicationEventMulticaster != null) {
addListener(listener); this.applicationEventMulticaster.addApplicationListener(listener);
} }
else { else {
this.applicationListeners.add(listener); this.applicationListeners.add(listener);
...@@ -838,8 +838,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader ...@@ -838,8 +838,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
/** /**
* Subclasses can invoke this method to register a listener. * Subclasses can invoke this method to register a listener.
* Any beans in the context that are listeners are automatically added. * 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 * @param listener the listener to register
* @deprecated as of Spring 3.0, in favor of {@link #addApplicationListener}
*/ */
@Deprecated
protected void addListener(ApplicationListener listener) { protected void addListener(ApplicationListener listener) {
getApplicationEventMulticaster().addApplicationListener(listener); getApplicationEventMulticaster().addApplicationListener(listener);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册