Spring 会话处理:未收到 HttpSessionDestroyedEvent [英] Spring session handling: HttpSessionDestroyedEvent not received
问题描述
我有一个 Web 应用程序,其中在 web.xml
中添加了 HttpSessionEventPublisher
作为侦听器.Web 应用程序在 Jetty 7.x 上运行,我们使用的是 Spring 3.1.1.
I have a web app where in the web.xml
I have added the HttpSessionEventPublisher
as listener. The web app runs on Jetty 7.x and we are using Spring 3.1.1.
这应该将 HttpSessionCreatedEvent
和 HttpSessionDestroyedEvent
触发到 Spring 上下文事件侦听器.
This is supposed to fire HttpSessionCreatedEvent
and HttpSessionDestroyedEvent
to Spring context event listeners.
我有一个实现 ApplicationListener
的 Bean (@Controller
).ApplicationEvent
是HttpSessionCreatedEvent
和HttpSessionDestroyedEvent
的公共父类.当我现在登录到我的 Web 应用程序或从中注销时,我希望这些事件被触发到 onApplicationEvent(ApplicationEvent event)
方法.我收到了其他事件,比如一些请求处理事件,但没有出现预期的事件.我已经稍微跟踪了该应用程序,HttpSessionEventPublisher
肯定会将事件触发到上下文,但没有接近侦听器.我在这里想念什么?
I have a Bean (@Controller
) that implements ApplicationListener<ApplicationEvent>
. ApplicationEvent
is the common parent class of HttpSessionCreatedEvent
and HttpSessionDestroyedEvent
. When I now login to my web application or log out from it I'd expect these events to be fired to the onApplicationEvent(ApplicationEvent event)
method. I have received other events like some request handling event, but the expected event's didn't show up. I have traced the app a bit, the HttpSessionEventPublisher
definitely fires the event to the context, but the listener isn't approached. what do I miss here?
推荐答案
问题在于 HttpSessionEventPublisher
根据 javadoc 在Spring Root WebApplicationContext"上发布事件,这是通过
The issue is that HttpSessionEventPublisher
publishes events on the "Spring Root WebApplicationContext" per the javadoc, this is the application context registered through ContextLoaderListener
entry in your web.xml file. Your @Controller on the other hand is probably registered through a different application context altogether - the one registered through the DispatcherServlet. So I would suggest that you create a different ApplicationListener, register it to the Root WebapplicationContext, the events should come through then.
这篇关于Spring 会话处理:未收到 HttpSessionDestroyedEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!