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.
This is supposed to fire HttpSessionCreatedEvent
and HttpSessionDestroyedEvent
to Spring context event listeners.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With