在使用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包下,所以.......