集中回滚使用@transactional [英] Centralized rollback-for using @transactional
问题描述
是否可以在使用 @transactional
时告诉 Spring 回滚 XML 配置中的异常 MyException
以及 RuntimeException
?>
我知道可以在注释中设置回滚,但如果我有很多服务都设置相同的异常,这似乎是多余的.
我看到人们建议创建自定义事务注释,但我不想使用自定义注释并坚持使用 Spring 注释.
我知道可以使用建议,但从未见过可以同时使用注释的示例.
你可以通过使用 spring 事务建议标签来简单地实现这一点:
<tx:属性><tx:method name="*" rollback-for="MyException" no-rollback-for="OtherException"/></tx:attributes></tx:建议>
查看 Spring doc 事务管理部分以获取更多详细信息:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
Is it possible to tell Spring to rollback for exception MyException
as well as RuntimeException
in the XML configuration while using @transactional
?
I know it is possible to set the rollback for in the annotation but it seems redundant if I have lots of services that would all set the same exceptions.
I saw peoples suggesting to create a custom transactional annotation but I'd prefer not to use a custom annotation and stick with a Spring one.
I know that its possible to use advices but never saw examples where you can use the annotation at the same time.
you can simply achieve this by using spring transaction advice tags:
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="*" rollback-for="MyException" no-rollback-for="OtherException"/>
</tx:attributes>
</tx:advice>
check Spring doc transaction management section for more details: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
这篇关于集中回滚使用@transactional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!