Skip to content

Commit 961574b

Browse files
committed
Fix regression in determineTransactionManager
One more (and hopefully last) attempt at making sure determineTransactionManager does not break existing use cases. This commit prevents any lookup if no transaction attributes are set which is more compliant with the original version and prevents a lookup if a non existing bean name is provided explicitly (as it can be the case with Spring Boot). Issue: SPR-12541
1 parent 4a0ac97 commit 961574b

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -349,35 +349,30 @@ protected void clearTransactionManagerCache() {
349349
* Determine the specific transaction manager to use for the given transaction.
350350
*/
351351
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
352-
if (this.beanFactory != null) {
353-
String qualifier = txAttr != null ? txAttr.getQualifier() : null;
354-
if (StringUtils.hasText(qualifier)) {
355-
return determineQualifiedTransactionManager(qualifier);
356-
}
357-
else if (StringUtils.hasText(this.transactionManagerBeanName)) {
358-
return determineQualifiedTransactionManager(this.transactionManagerBeanName);
359-
}
360-
else if (txAttr != null) { // Do not lookup default bean name if no tx attributes are set
361-
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
362-
if (defaultTransactionManager == null) {
363-
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
364-
this.transactionManagerCache.putIfAbsent(
365-
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
366-
}
367-
return defaultTransactionManager;
352+
// Do not attempt to lookup tx manager if no tx attributes are set
353+
if (txAttr == null || this.beanFactory == null) {
354+
return getTransactionManager();
355+
}
356+
String qualifier = (txAttr.getQualifier() != null ?
357+
txAttr.getQualifier() : this.transactionManagerBeanName);
358+
if (StringUtils.hasText(qualifier)) {
359+
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
360+
if (txManager == null) {
361+
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
362+
this.beanFactory, PlatformTransactionManager.class, qualifier);
363+
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
368364
}
365+
return txManager;
369366
}
370-
return getTransactionManager();
371-
}
372-
373-
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
374-
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
375-
if (txManager == null) {
376-
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
377-
this.beanFactory, PlatformTransactionManager.class, qualifier);
378-
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
367+
else {
368+
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
369+
if (defaultTransactionManager == null) {
370+
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
371+
this.transactionManagerCache.putIfAbsent(
372+
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
373+
}
374+
return defaultTransactionManager;
379375
}
380-
return txManager;
381376
}
382377

383378
/**

0 commit comments

Comments
 (0)