When we use spring, we use his declarative transactions very often, simply make some rule configurations in the configuration file, and take advantage of Spring's AOP capabilities to easily handle transactional problems; Here is a question about the propagation properties of a transaction "propagation", He defined in the Transactiondefinition interface, interested to see SRC, there are 7 options available:
Propagation_required: Supports the current transaction, and creates a new transaction if there are currently no transactions. This is the most common choice.
Propagation_supports: Supports the current transaction and executes it in a non transactional manner if there are currently no transactions.
Propagation_mandatory: Supports the current transaction and throws an exception if there are currently no transactions.
Propagation_requires_new: Creates a new transaction, suspends the current transaction if there is currently a transaction.
Propagation_not_supported: Performs an operation in a non transactional manner and suspends the current transaction if there is currently a transaction.
Propagation_never: Executes in a non transactional manner and throws an exception if there is a current transaction.
Propagation_nested: Supports current transaction, adds new savepoint point, commits or rolls back synchronously with current transaction.
Now with an example, apply the above various propagation properties to illustrate: First, declare two bean:servicea and SERVICEB, wherein SERVICEB is referenced;
view plaincopy to clipboardprint?
ServiceA {
void methodA() {
ServiceB.methodB();
}
}
ServiceB {
void methodB() {
// ...
}
}
ServiceA {
void methodA() {
ServiceB.methodB();
}
}
ServiceB {
void methodB() {
// ...
}
}