如何解决@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 举报,一经查实,本站将立刻删除。