ajjjian 2008-12-10 15:35 采纳率: 0%
浏览 418
已采纳

spring2事务中使用手工抛出异常不回滚

我使用spring的声明式事务,为一个包的下的所有*Manager的所有方法声明了事务管理,当我在一个方法里使用throw new Exception("error");手工抛出异常时,事务没有回滚,但当我在代码中间加上使用一个除以零的代码时,系统抛出by zero的异常,事务正常回滚了。相关配置如下:[code="java"]

    <aop:advisor pointcut="execution(* com.prize.service.*Manager.*(..))" advice-ref="txAdvice"/>
    </aop:config>

    <tx:advice id="txAdvice">
    <tx:attributes>
        <tx:method name="get*" read-only="true"/>
        <tx:method name="find*" read-only="true"/>
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>[/code]

请问是什么原因?如何手工让事务回滚呢?

  • 写回答

2条回答 默认 最新

  • tomcatacec 2008-12-13 05:29
    关注

    spring 文档的描述非常清楚:
    http://static.springframework.org/spring/docs/2.5.x/reference/transaction.html#transaction-declarative

    EJB CMT does not roll back the transaction automatically on an application exception (that is, a checked exception other than java.rmi.RemoteException). While the Spring default behavior for declarative transaction management follows EJB convention (roll back is automatic only on unchecked exceptions), it is often useful to customize this.
    默认对unchecked exception进行回滚。

    也可以对规定的checked exception进行回滚:

    tx:attributes


    /tx:attributes
    /tx:advice

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?