是否可以告诉Spring回滚异常MyException
也RuntimeException
使用时在 XML 配置中@transactional
?
我知道可以在注释中设置回滚,但如果我有很多服务都设置相同的异常,那么这似乎是多余的。
我看到人们建议创建一个自定义事务注释,但我不想使用自定义注释并坚持使用 Spring 注释。
我知道可以使用建议,但从未见过可以同时使用注释的示例。
您可以通过使用 Spring 事务建议标签来简单地实现这一点:
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="*" rollback-for="MyException" no-rollback-for="OtherException"/>
</tx:attributes>
</tx:advice>
查看 Spring 文档事务管理部分以获取更多详细信息:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)