加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

春季-当受检查的异常在事务中传播时会发生什么?

发布时间:2020-12-15 01:21:55 所属栏目:大数据 来源:网络整理
导读:我知道在发生RuntimeExceptions时,事务管理器中的默认回滚策略是自动回滚.但是,如果我有一个允许传播的检查异常会怎样? 最佳答案 However,please note that the Spring Frameworks transaction infrastructure code will,by default,only mark a transactio

我知道在发生RuntimeExceptions时,事务管理器中的默认回滚策略是自动回滚.但是,如果我有一个允许传播的检查异常会怎样?

最佳答案

However,please note that the Spring Framework’s transaction
infrastructure code will,by default,only mark a transaction for
rollback in the case of runtime,unchecked exceptions; that is,when
the thrown exception is an instance or subclass of RuntimeException.
(Errors will also – by default – result in a rollback.) Checked
exceptions that are thrown from a transactional method will not result
in the transaction being rolled back.

Source

即使抛出了检查异常,Spring也会提交事务,就好像一切都很好.
如果需要,您可以配置已检查异常的回滚.
喜欢

<tx:advice id="txAdvice" transaction-manager="txManager">
  <tx:attributes>
     <tx:method name="get*" read-only="false" rollback-for="AnyCheckedException"/>
     <tx:method name="*"/>
  </tx:attributes>
</tx:advice>

抛出AnyCheckedException时将执行回滚.

这可能会有所帮助:Spring transaction management with checked and unchecked exception

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读