Usage
Adding the @Transactional annotation at the class level or method level.
1 |
|
Implementation
Spring will create a Proxy class by AOP when detects the Annotated class/method runs, it will:
- start the transaction
- run the business logic
- commit the transaction or rollback
Exception handling
If RunTimeException thrown, the Proxy will roll back the transaction, otherwise(no exception thrown or no-RunTimeException thrown), the Proxy will commit the transaction.
But you can also rollback the transaction by rollbackFor property, for example:
1 |