AbstractApplicationContext-publishEvent-method中的错误?

时间:2014-12-12 14:42:55

标签: java spring spring-mvc bug-reporting

我认为AbstractApplicationContext类的方法publishEvent中存在一个错误:

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);
    }
}

在MVC应用程序中,有一个spring-context-hierarchy,root-and context-context。如果我刷新子上下文,那么这个方法也会刷新父上下文。但它不能使用相同的ApplicationEvent对象,因为它包含引用上下文的source属性,它已被刷新:

/**
 * 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();
}

所以,我认为这是错误的,如果父(根)上下文发送一个事件并说,那个子上下文被刷新了。 例如,类SourceFilteringListener使用此属性来决定是否应该传递事件:

public void onApplicationEvent(ApplicationEvent event) {
    if (event.getSource() == this.source) {
        onApplicationEventInternal(event);
    }
}

我的假设是否正确(这是一个错误)??? 我之所以这么认为是因为我调查了我的MVC应用程序中的一个错误,并试图找出一些组件没有收到刷新事件的原因。

0 个答案:

没有答案
相关问题