日期:2014-05-16 浏览次数:20409 次
public Object findBean(String beanname, ServletContext context) { ApplicationContext appctx = WebApplicationContextUtils .getRequiredWebApplicationContext(context); return appctx.getBean(beanname); }
public void sessionBindThread(ServletContext context) throws Exception { SessionFactory factory = (SessionFactory) findBean( "FactoryName", context); Session sInfo = SessionFactoryUtils.getSession(factory, true); if(TransactionSynchronizationManager.getResource(factory) == null){ TransactionSynchronizationManager .bindResource(factory,new SessionHolder(sInfo)); } }
public void sessionOutThread(ServletContext context) throws Exception { SessionFactory factory = (SessionFactory) findBean( "FactoryName", context); SessionHolder holderInfo = (SessionHolder) TransactionSynchronizationManager .getResource(factory); if(holderInfo!=null){ Session s = holderInfo.getSession(); s.flush();//不想提交用s.clear() TransactionSynchronizationManager.unbindResource(factory); SessionFactoryUtils.releaseSession(s, factory); } }