In the Spring declarative transaction manager: My configuration tx:method:
<tx:method name="handle*" propagation="REQUIRED" no-rollback-for="java.lang.RuntimeException" rollback-for="java.lang.Exception" read-only="false"/>
Spring
rollback-for documentation is : The Exception(s) that will trigger rollback; comma-delimited. For example, 'com.foo.MyBusinessException,ServletException'no-rollback-for documentation is: The Exception(s) that will not trigger rollback; comma-delimited. For example, 'com.foo.MyBusinessException,ServletException'
I开发者_开发百科 want the transaction manager rollback when catch the java.lang.Exception but the java.lang.RuntimeException will result commit.
Is this configuration work for my request? what relationship about : no-rollback-for and rollback-for in tx:method of tx:advice?
In short
It does what you want.
The most specific (no)-rollback-for rule that match the concreate throwing exception is winning.
This mean if you have an exception hierarchy and the rollback rules
- A (extends Exception) <-- rollback
- B extends A
- C extends B <-- no rollback
- D extends C
- E extends D <-- rollback
- F extends E
Then an thrown exception of class A, B, E and F will rollback, but C and D will not.
(It is implemented in RuleBasedTransactionAttribute.rollBackOn(Throwable ex)
)
精彩评论