日期:2014-05-20  浏览次数:20669 次

struts2+spring+hibernate使用HttpSessionBindingListener监听session时
struts2+spring+hibernate使用HttpSessionBindingListener监听session时,如果session销毁时,如何在这个监听类里如果把信息写入数据库?也就是在session销毁时,还要操作DAO,可是如何让继承HttpSessionBindingListener的这个类在操作DAO时让Spring把sessionFactory注入到DAO中呢?
如果不行,那还有什么办法让session销毁时,自动操作操作库呢?求高人指点,本人万分感激。。

------解决方案--------------------
在HttpSessionBindingListener的实现类中用WebApplicationUtils.getRequireWebApplictionContext(ServletContext sc);得到ApplictionContext,在getBean
------解决方案--------------------
try:

public void valueUnbound(HttpSessionBindingEvent sessionEvent) {
// TODO Auto-generated method stub
ServletContext sc =sessionEvent.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicati onContext(sc);

SomeDao sd =(SomeDao)ctx.getBean("someDao");
}
------解决方案--------------------
探讨

try:

public void valueUnbound(HttpSessionBindingEvent sessionEvent) {
// TODO Auto-generated method stub
ServletContext sc =sessionEvent.getSession().getServletContext();
ApplicationContext ctx……