spring-framework / org.springframework.test.context.transaction / TestContextTransactionUtils / retrieveTransactionManager

retrieveTransactionManager

@Nullable open static fun retrieveTransactionManager(testContext: TestContext, @Nullable name: String): PlatformTransactionManager

Retrieve the PlatformTransactionManager to use for the supplied TestContext.

The following algorithm is used to retrieve the transaction manager from the org.springframework.context.ApplicationContext of the supplied test context:

  1. Look up the transaction manager by type and explicit name, if the supplied name is non-empty, throwing a BeansException if the named transaction manager does not exist.
  2. Attempt to look up the single transaction manager by type.
  3. Attempt to look up the primary transaction manager by type.
  4. Attempt to look up the transaction manager via a TransactionManagementConfigurer, if present.
  5. Attempt to look up the transaction manager by type and the default transaction manager.

Parameters

testContext - the test context for which the transaction manager should be retrieved; never null

name - the name of the transaction manager to retrieve; may be null or empty

Exceptions

BeansException - if an error occurs while retrieving an explicitly named transaction manager

IllegalStateException - if more than one TransactionManagementConfigurer exists in the ApplicationContext

Return
the transaction manager to use, or null if not found