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

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

概述我知道在发生RuntimeExceptions时,事务管理器中的默认回滚策略是自动回滚.但是,如果我有一个允许传播的检查异常会怎样?最佳答案 However, please note that the Spring Framework's transaction infrastructure code will, by default, only m

我知道在发生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 总结

以上是内存溢出为你收集整理的春季-当受检查的异常在事务中传播时会发生什么? 全部内容,希望文章能够帮你解决春季-当受检查的异常在事务中传播时会发生什么? 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1239822.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存