在使用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); } ...