Spring supports two ways of "programmatic transaction management" and "Declarative transaction Management ".
Declarative transactions
Declarative transaction management is built on the AOP. The essence is to intercept the method before and after it, and then create or join a transaction before the target method starts, committing or rolling back the transaction according to execution after the target method is executed.
The greatest advantage of declarative transactions is that you do not need to programmatically manage transactions, so that you do not need to doping transaction-managed code in your business logic code, just make relevant transaction rule declarations in the configuration file (or through @transactional annotations). You can apply transaction rules to the business logic.
Transactional propagation behavior
The so-called transaction propagation behavior is that if a transaction context already exists before the current transaction is started, there are several options to specify the execution behavior of a transactional method. The transactiondefinition definition includes the following constants that represent propagation behavior:
Transactiondefinition.propagation_REQUIRED: If a transaction is currently present, the transaction is joined and a new transaction is created if there is no current transaction. This is the default value.
Transactiondefinition.propagation_requires_new: Creates a new transaction and suspends the current transaction if a transaction is currently present.
Transactiondefinition.propagation_SUPPORTS: If a transaction is currently present, the transaction is joined, and if no transaction is currently present, it will continue in a non-transactional manner.
Transactiondefinition.propagation_not_supported: Runs in a non-transactional manner, suspending the current transaction if a transaction is currently present.
Transactiondefinition.propagation_never: Runs in a non-transactional manner and throws an exception if a transaction is currently present.
Transactiondefinition.propagation_MANDATORY: If a transaction is currently present, the transaction is joined and an exception is thrown if there is no current transaction.
Transactiondefinition.propagation_NESTED: If a transaction is currently present, create a transaction to run as a nested transaction for the current transaction, or if there is no current transaction, The value is equivalent to transactiondefinition.propagation_required.
Reference: Spring Transaction description
Spring's @transactional annotations