1

我有三个 bean,都具有相同的方法签名:

import javax.ejb.Singleton;
import javax.ejb.Startup;
@Startup    //  Eager initialization
@Singleton
public class ApplicationManager
{
    private void onRemoveUserLoginSession(@Observes @Removed UserLoginSession userLoginSession) {
        logger.info("ApplicationManager.onRemoveUserLoginSession");
    }

}

@SessionScoped
public class ManageEventOrWorkflowNotFoundLogConversations
{
    private void onRemoveUserLoginSession(@Observes @Removed UserLoginSession userLoginSession) {
        logger.info("ManageEventOrWorkflowNotFoundLogConversations.onRemoveUserLoginSession");
    }
}

@Dependent
public class ManageEventOrWorkflowNotFoundLogConversation
{
    private void onRemoveUserLoginSession(@Observes @Removed UserLoginSession userLoginSession) {
        logger.info("ManageEventOrWorkflowNotFoundLogConversation.onRemoveUserLoginSession");
    }
}

当事件触发时,只有 ApplicationManager#onRemoveUserLoginSession 的事件观察者接收到事件(例如,其他两个方法都没有接收到事件)。

当我在 ApplicationManager 中删除事件观察器时,其他两个方法中的每一个都会接收到事件。

@Startup    //  Eager initialization
@Singleton
public class ApplicationManager
{
    private void onRemoveUserLoginSession(UserLoginSession userLoginSession) {
        logger.info("ApplicationManager.onRemoveUserLoginSession");
    }

}

这是触发事件的bean:

@SessionScoped
public class SessionManager implements UserLoginSession
{
    @Inject @Removed Event<UserLoginSession> sessionRemovedEvent;

    @PreDestroy private void sessionDestroyed() {
        this.sessionRemovedEvent.fire(this);
    }
}

为什么会这样?

4

0 回答 0