Search code examples
springjta

Spring transactions


I have written a custom REST compensation framework in spring which records a REST call along with compensation call info (using annotations and AOP) which will be executed if there is a exception the down the line.

E.g rest call 1 (success) -> rest call 2 (failed) -> rest call 1 compensation.

The application also uses JTA transactions. Can I extend JTA transaction manager to call the compensation framework logic if the JTA transaction is rolled back?


Solution

  • You can register a TransactionSynchronization (Spring's TransactionSynchronizationManager gives you a wrapper around the JTA feature that works in non JTA environments as well). Would it be easier to use AOP to deal with the exception independent of the transaction, since you are using AOP already?