I'm just documenting somehting on the ContextClosedEvent. It's called
when all singletons have been destroyed (i.e. destroy method has been
called)
public void close() {
if (logger.isInfoEnabled()) {
logger.info("Closing application context [" +
getDisplayName() + "]");
}
// Destroy all cached singletons in this context,
// invoking DisposableBean.destroy and/or "destroy-method".
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
if (beanFactory != null) {
beanFactory.destroySingletons();
}
// publish corresponding event
publishEvent(new ContextClosedEvent(this));
}
I've personally never used the context closed event, but what I have to
ask here is, does nobody else think this sequence is not usable and/or
potentially dangerous. On the not usable part, an event listener must
not have a destroy method, since the onApplicationEvent() would end up
being called after the bean has been destroyed. As for potentially
dangerous, that's if somebody forgets that they can't have a destroy
method, and then spring does call the two methods in the wrong sequence.
Colin
|