@EventListener 不触发 SessionDestroyedEvent

问题描述

我试图在 Spring 的 SessionDestroyedEvent 上运行一些代码。但是无论我注销还是等待会话超时,我的侦听器都不会接收到此事件。查看stackoverflow,我发现这个问题并不少见,通常很容易解决,但我尝试了许多不同的解决方案,但没有任何效果。我确实看到在应用程序启动时创建了 bean。根据文档,我相信我只需要以下侦听器:

@Component
public class logoutListener {

    @EventListener
    void handleSessionDestroyedEvent(SessionDestroyedEvent event){
        log.debug("handling destroyed event");
    }
} 

我已将以下内容添加到 ApplicationConfig 中,尽管我不确定是否有必要。

@Configuration
public class ApplicationConfig {
    @Bean
    public ServletListenerRegistrationBean<HttpSessionEventPublisher> httpSessionEventPublisher() {
        return new ServletListenerRegistrationBean<HttpSessionEventPublisher>(new HttpSessionEventPublisher());
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)