Spring会话处理:未收到HttpSessionDestroyeEvent

Spring会话处理:未收到HttpSessionDestroyeEvent,spring,session,web-applications,Spring,Session,Web Applications,我有一个web应用程序,其中在web.xml中添加了HttpSessionEventPublisher作为侦听器。该web应用程序在Jetty 7.x上运行,我们使用的是Spring 3.1.1 这应该触发HttpSessionCreatedEvent和HttpSessionDestroyedEvent到Spring上下文事件侦听器 我有一个Bean(@Controller),它实现了ApplicationListenerApplicationEvent是HttpSessionCreatedEv

我有一个web应用程序,其中在
web.xml
中添加了
HttpSessionEventPublisher
作为侦听器。该web应用程序在Jetty 7.x上运行,我们使用的是Spring 3.1.1

这应该触发
HttpSessionCreatedEvent
HttpSessionDestroyedEvent
到Spring上下文事件侦听器


我有一个Bean(
@Controller
),它实现了
ApplicationListener
ApplicationEvent
HttpSessionCreatedEvent
HttpSessionDestroyedEvent
的通用父类。当我现在登录到我的web应用程序或从中注销时,我希望这些事件会被激发到ApplicationEvent(ApplicationEvent事件)方法。我收到了其他事件,如一些请求处理事件,但预期的事件没有出现。我对应用程序进行了一点跟踪,
HttpSessionEventPublisher
肯定会将事件触发到上下文中,但是没有找到侦听器。这里我遗漏了什么?

问题是
HttpSessionEventPublisher
根据javadoc在“Spring Root WebApplicationContext”上发布事件,这是通过web.xml文件中的
ContextLoaderListener
条目注册的应用程序上下文。另一方面,@Controller可能是通过一个完全不同的应用程序上下文注册的,即通过DispatcherServlet注册的应用程序上下文。因此,我建议您创建一个不同的ApplicationListener,将其注册到根WebapplicationContext,然后事件就会发生。

面对类似的问题,如果无法将ApplicationListener移动到根上下文,您可以使用org.springframework.security.context.DelegatingApplicationListener

只需在Bean中自动连接一个DelegatingApplicationListener,并使用constructor/@PostConstruct根据DelegatingApplicationListener注册您的侦听器(spring security应该已经准备好了一个)