Support TransactionManagementConfigurer in the TCF
Currently the Spring TestContext Framework looks up a PlatformTransactionManager bean named "transactionManager". The exact name of the bean can be overridden via @TransactionConfiguration or @Transactional; however, the bean will always be looked up 'by name'. The TransactionManagementConfigurer interface that was introduced in Spring 3.1 provides a programmatic approach to specifying the PlatformTransactionManager bean to be used for annotation-driven transaction management, and that bean is not required to be named "transactionManager". However, as of Spring 3.1.2, using the TransactionManagementConfigurer on a @Configuration class has no effect on how the TestContext framework looks up the transaction manager. Consequently, if an explicit name or qualifier has not been specified, the bean must be named "transactionManager" in order for a transactional integration test to work. This commit addresses this issue by refactoring the TransactionalTestExecutionListener so that it looks up and delegates to a single TransactionManagementConfigurer as part of the algorithm for determining the transaction manager. Issue: SPR-9604
This commit is contained in:
@@ -630,9 +630,9 @@ public class CustomTestExecutionListenerTests {
|
||||
|
||||
<para>Defines class-level metadata for configuring transactional
|
||||
tests. Specifically, the bean name of the
|
||||
<interfacename>PlatformTransactionManager</interfacename> that is
|
||||
to be used to drive transactions can be explicitly specified if
|
||||
there are multiple beans of type
|
||||
<interfacename>PlatformTransactionManager</interfacename> that
|
||||
should be used to drive transactions can be explicitly specified
|
||||
if there are multiple beans of type
|
||||
<interfacename>PlatformTransactionManager</interfacename> in the
|
||||
test's <interfacename>ApplicationContext</interfacename> and the
|
||||
bean name of the desired
|
||||
@@ -657,9 +657,12 @@ public class CustomConfiguredTransactionalTests {
|
||||
configuration, you can avoid using
|
||||
<interfacename>@TransactionConfiguration</interfacename>
|
||||
altogether. In other words, if you have only one transaction
|
||||
manger (or your transaction manager bean is named
|
||||
"transactionManager") and if you want transactions to roll back
|
||||
automatically, there is no need to annotate your test class with
|
||||
manger — or if you have multiple transaction mangers but the
|
||||
transaction manager for tests is named "transactionManager" or
|
||||
specified via a
|
||||
<interfacename>TransactionManagementConfigurer</interfacename> —
|
||||
and if you want transactions to roll back automatically, then
|
||||
there is no need to annotate your test class with
|
||||
<interfacename>@TransactionConfiguration</interfacename>.</para>
|
||||
</note>
|
||||
</listitem>
|
||||
|
||||
Reference in New Issue
Block a user