在使用sessionFactory.getCurrentSession();时,提示找不到当前sessionjava
该问题的产生是因为sessionFatory未可以正确注册。express
具体缘由以下:session
须要配置事务bean,具体以下:ide
<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="ServiceOperation" expression="execution(* com.cml.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="ServiceOperation" /> </aop:config>
再到 Service 中配置code
... @Override @Transactional(propagation=Propagation.SUPPORTS, readOnly=false)//加上这一句 public boolean addOrUpdateUser(User user) { return userDao.addOrUpdateUser(user); } ...