我有三个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);
}
}
为什么会这样?