Centralized rollback-for using @transactional

点点圈 提交于 2020-01-15 05:04:08

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/14979875/centralized-rollback-for-using-transactional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!