异常:Could not obtain transaction-synchronized Session for current thread
两种情况:
1、 新加的业务方法不在事务传播特性限定的方法名中
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="select*" propagation="REQUIRED"/>
<tx:method name="load*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
2、 新加的业务层目录在配置事务切面的时候没有扫描到
<aop:config expose-proxy="true">
<aop:pointcut id="txPointcut" expression="execution(* com..service.spring.*.* (..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" order="500"/>
</aop:config>

本文解析了Spring框架中出现的Couldnotobtaintransaction-synchronizedSessionforcurrentthread异常的原因,并提供了两种解决方案:一是检查业务方法是否符合事务传播特性的限定;二是确认业务层目录是否被正确扫描以应用事务切面。
4598

被折叠的 条评论
为什么被折叠?



