天天看點

關于struts+spring4+hibernate4整合是出現的No Session found for current thread解決

在使用struts2+spring4+hibernate4出現了No Session found for current   thread

在網上查說是配上這個

<

prop

key

=

"hibernate.current_session_context_class"

>thread</

prop

>

,但當我測試時發現有出現了org.hibernate.HibernateException:No CurrentSessionContext configured!或save is not valid without active transacton

處理這個問題處理好久沒解決,我原來的做法是service直接繼承BaseDao和BaseDaoImpl,其中BaseDao和BaseDaoImpl在com.xyc.mt.base裡,service在com.xyc.mt.service

<!-- 配置事務切面 -->

<aop:config>

<aop:pointcut id="serviceOperation"

expression="execution(* com.xyc.mt.service..*.*(..))" />

<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />

</aop:config>

後來因為這個錯誤,我有抽取了BaseService和BaseServiceImpl并放在了com.xyc.mt.base包裡,結果一樣報上面的錯誤,後來我突發奇想把BaseService和BaseServiceImpl移到了com.xyc.mt.service,結果問題解決,測試通過,不在報錯了

是以發現問題,因為我配的事務在com.xyc.mt.service包下,是以.......

繼續閱讀