Align TransactionManagementConfigurer support in TCF with production

This commit picks up where 613bd3be1d
left off by ensuring that a transaction manager configured via the
TransactionManagementConfigurer API takes precedence over any
transaction manager configured as a bean in the ApplicationContext
unless @Transactional is configured with a qualifier for the explicit
transaction manager to use in tests.

Closes gh-24869
This commit is contained in:
Sam Brannen
2020-05-11 13:59:34 +02:00
parent 65acda8d3e
commit 715e8c9ef6
3 changed files with 153 additions and 7 deletions

View File

@@ -183,13 +183,6 @@ public abstract class TestContextTransactionUtils {
if (bf instanceof ListableBeanFactory) {
ListableBeanFactory lbf = (ListableBeanFactory) bf;
// Look up single bean by type
Map<String, PlatformTransactionManager> txMgrs =
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
if (txMgrs.size() == 1) {
return txMgrs.values().iterator().next();
}
// Look up single TransactionManagementConfigurer
Map<String, TransactionManagementConfigurer> configurers =
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, TransactionManagementConfigurer.class);
@@ -203,6 +196,13 @@ public abstract class TestContextTransactionUtils {
return (PlatformTransactionManager) tm;
}
// Look up single bean by type
Map<String, PlatformTransactionManager> txMgrs =
BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, PlatformTransactionManager.class);
if (txMgrs.size() == 1) {
return txMgrs.values().iterator().next();
}
try {
// Look up single bean by type, with support for 'primary' beans
return bf.getBean(PlatformTransactionManager.class);