类 TransactionSynchronizationManager


  • public class TransactionSynchronizationManager
    extends Object
    Central delegate that manages resources and transaction synchronizations per subscriber context. To be used by resource management code but not by typical application code.

    Supports one resource per key without overwriting, that is, a resource needs to be removed before a new one can be set for the same key. Supports a list of transaction synchronizations if synchronization is active.

    Resource management code should check for context-bound resources, e.g. database connections, via getResource. Such code is normally not supposed to bind resources to units of work, as this is the responsibility of transaction managers. A further option is to lazily bind on first use if transaction synchronization is active, for performing transactions that span an arbitrary number of resources.

    Transaction synchronization must be activated and deactivated by a transaction manager via initSynchronization() and clearSynchronization(). This is automatically supported by AbstractReactiveTransactionManager, and thus by all standard Spring transaction managers.

    Resource management code should only register synchronizations when this manager is active, which can be checked via isSynchronizationActive(); it should perform immediate resource cleanup else. If transaction synchronization isn't active, there is either no current transaction, or the transaction manager doesn't support transaction synchronization.

    Synchronization is for example used to always return the same resources within a transaction, e.g. a database connection for any given connection factory.

    从以下版本开始:
    5.2
    作者:
    Mark Paluch, Juergen Hoeller
    另请参阅:
    isSynchronizationActive(), registerSynchronization(org.springframework.transaction.reactive.TransactionSynchronization), TransactionSynchronization