I think there is a bug in method publishEvent of class AbstractApplicationContext:
public void publishEvent(ApplicationEvent event) {
Assert.notNull(event, "Event must not be null");
if (logger.isTraceEnabled()) {
logger.trace("Publishing event in " + getDisplayName() + ": " + event);
}
getApplicationEventMulticaster().multicastEvent(event);
if (this.parent != null) {
this.parent.publishEvent(event);
}
}
In a MVC-application there is a spring-context-hierarchy, root- and child-context. If i refresh child-context, then this method would refresh parent-context too. BUT it must not do it with the same ApplicationEvent-object as it contains source property that references the context, that was refreshed:
/**
* Create a new ApplicationEvent.
* @param source the component that published the event (never {@code null})
*/
public ApplicationEvent(Object source) {
super(source);
this.timestamp = System.currentTimeMillis();
}
So, i think it is wrong, if parent (root) context sends a event and says, that child-context was refreshed. There is for example class SourceFilteringListener that uses this property to decide, if an event should be delivered:
public void onApplicationEvent(ApplicationEvent event) {
if (event.getSource() == this.source) {
onApplicationEventInternal(event);
}
}
Is my assumption correct (and it is a bug) ??? The reason why i think so is that i investigate a bug in my MVC-application, and i try to find out why some component did not receive refresh-event.