How to inject dependencies into HttpSessionListener, using Spring and without calls, like context.getBean("foo-bar")
?
views:
578answers:
1
+3
A:
You can declare your HttpSessionListener
as a bean in Spring context, and register a delegation proxy as an actual listener in web.xml
, something like this:
public class DelegationListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
ApplicationContext context =
WebApplicationContextUtils.getWebApplicationContext(
se.getSession().getServletContext()
);
HttpSessionListener target =
context.getBean("myListener", HttpSessionListener.class);
target.sessionCreated(se);
}
...
}
axtavt
2010-03-12 14:41:35
That's fine solution, I wonder why there's no such DelegationListener in Spring itself.
Shaman
2010-03-12 19:13:16