Q: Do I not roll back when an exception is thrown in spring service?
Spring transactions:
By default, spring containers roll back transactions for non-checked exceptions (non-checked exceptions thrown in the service module. The transaction is committed for the query exception.
For spring, declarative transactions can set transaction boundaries (Propagation Behavior), isolation levels, read-only transactions, and rollback rules (+: commit for any exceptions ,-: rollback for any exceptions)
<Property name = "transactionattributes">
<Props>
<Prop key = "*"> + exception Type 1,-exception type 2 </prop>
</Property>
Example:
Bean id = "transactionattributes"
Class = "org. springframework. transaction. Interceptor. namematchtransactionattributesource">
<Property name = "properties">
<Value>
Do * = propagation_required,-exception
Get * = propagation_required, readonly
Search * = propagation_required, readonly
</Value>
</Property>
</Bean>
Add-exception