diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java
index d00370dcf34..c71e2ec106d 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TestContextTransactionUtils.java
@@ -145,9 +145,9 @@ public abstract class TestContextTransactionUtils {
* {@code name} is non-empty, throwing a {@link BeansException} if the named
* transaction manager does not exist.
*
Attempt to look up the single transaction manager by type.
- * Attempt to look up the primary transaction manager by type.
* Attempt to look up the transaction manager via a
* {@link TransactionManagementConfigurer}, if present.
+ * Attempt to look up the primary transaction manager by type.
* Attempt to look up the transaction manager by type and the
* {@linkplain #DEFAULT_TRANSACTION_MANAGER_NAME default transaction manager
* name}.
@@ -190,14 +190,6 @@ public abstract class TestContextTransactionUtils {
return txMgrs.values().iterator().next();
}
- try {
- // Look up single bean by type, with support for 'primary' beans
- return bf.getBean(PlatformTransactionManager.class);
- }
- catch (BeansException ex) {
- logBeansException(testContext, ex, PlatformTransactionManager.class);
- }
-
// Look up single TransactionManagementConfigurer
Map configurers =
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, TransactionManagementConfigurer.class);
@@ -210,6 +202,14 @@ public abstract class TestContextTransactionUtils {
"is not a PlatformTransactionManager: " + tm);
return (PlatformTransactionManager) tm;
}
+
+ try {
+ // Look up single bean by type, with support for 'primary' beans
+ return bf.getBean(PlatformTransactionManager.class);
+ }
+ catch (BeansException ex) {
+ logBeansException(testContext, ex, PlatformTransactionManager.class);
+ }
}
// look up by type and default name
diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/manager/LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/manager/LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests.java
index 05948d86464..d6e44d4b3e8 100644
--- a/spring-test/src/test/java/org/springframework/test/context/transaction/manager/LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/transaction/manager/LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests.java
@@ -34,9 +34,9 @@ import org.springframework.transaction.testfixture.CallCountingTransactionManage
import static org.assertj.core.api.Assertions.assertThat;
/**
- * Integration test that verifies the current behavior for transaction manager
- * lookups when one transaction manager is {@link Primary @Primary} and an
- * additional transaction manager is configured via the
+ * Integration test that verifies the behavior for transaction manager lookups
+ * when one transaction manager is {@link Primary @Primary} and an additional
+ * transaction manager is configured via the
* {@link TransactionManagementConfigurer} API.
*
* @author Sam Brannen
@@ -44,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringJUnitConfig
@Transactional
-// TODO Update assertions once https://github.com/spring-projects/spring-framework/issues/24869 is fixed.
class LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests {
@Autowired
@@ -57,28 +56,28 @@ class LookUpTxMgrViaTransactionManagementConfigurerWithPrimaryTxMgrTests {
@Test
void transactionalTest() {
- assertThat(primary.begun).isEqualTo(1);
- assertThat(primary.inflight).isEqualTo(1);
+ assertThat(primary.begun).isEqualTo(0);
+ assertThat(primary.inflight).isEqualTo(0);
assertThat(primary.commits).isEqualTo(0);
assertThat(primary.rollbacks).isEqualTo(0);
- assertThat(annotationDriven.begun).isEqualTo(0);
- assertThat(annotationDriven.inflight).isEqualTo(0);
+ assertThat(annotationDriven.begun).isEqualTo(1);
+ assertThat(annotationDriven.inflight).isEqualTo(1);
assertThat(annotationDriven.commits).isEqualTo(0);
assertThat(annotationDriven.rollbacks).isEqualTo(0);
}
@AfterTransaction
void afterTransaction() {
- assertThat(primary.begun).isEqualTo(1);
+ assertThat(primary.begun).isEqualTo(0);
assertThat(primary.inflight).isEqualTo(0);
assertThat(primary.commits).isEqualTo(0);
- assertThat(primary.rollbacks).isEqualTo(1);
+ assertThat(primary.rollbacks).isEqualTo(0);
- assertThat(annotationDriven.begun).isEqualTo(0);
+ assertThat(annotationDriven.begun).isEqualTo(1);
assertThat(annotationDriven.inflight).isEqualTo(0);
assertThat(annotationDriven.commits).isEqualTo(0);
- assertThat(annotationDriven.rollbacks).isEqualTo(0);
+ assertThat(annotationDriven.rollbacks).isEqualTo(1);
}