Spring有以下的事务机制:
/**
* Support a current transaction, create a new one if none exists.
*/
REQUIRED(TransactionDefinition.PROPAGATION_REQUIRED),
支持当前的事务,如果当前没有事务,就创建一个事务,它也是默认的事务机制。
/**
* Support a current transaction, execute non-transactionally if none exists.
*/
SUPPORTS(TransactionDefinition.PROPAGATION_SUPPORTS),
支持当前事务,如果不存在事务,则不执行事务。如果存在,则执行事务。
/**
* Support a current transaction, throw an exception if none exists.
*/
MANDATORY(TransactionDefinition.PROPAGATION_MANDATORY),
强制要求当前必须存在事务,如果不存在事务,则抛出异常
/**
* Create a new transaction, and suspend the current transaction if one exists.
*/
REQUIRES_NEW(TransactionDefinition.PROPAGATION_REQUIRES_NEW),
如果当前存在事务,则挂起该事务,并创建新一个新的事务。
/**
* Execute non-transactionally, suspend the current transaction if one exists.
*/
NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED),
如果当前存在事务,则挂起该事务。然后自身不使用事务
/**
* Execute non-transactionally, throw an exception if a transaction exists.
*/
NEVER(TransactionDefinition.PROPAGATION_NEVER),
如果当前存在事务,则抛出异常,相当于强制性的不使用事务
/**
* Execute within a nested transaction if a current transaction exists,
* behave like {@code REQUIRED} otherwise.
*/
NESTED(TransactionDefinition.PROPAGATION_NESTED);
如果当前存在事务,则创建一个嵌套的子事务。
Spring事务传播机制
最新推荐文章于 2024-03-09 14:10:04 发布