Browse Source

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
pull/713/head
Stephane Nicoll 11 years ago
parent
commit
961574bd17
  1. 31
      spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

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

@ -349,15 +349,22 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init @@ -349,15 +349,22 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
* Determine the specific transaction manager to use for the given transaction.
*/
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
if (this.beanFactory != null) {
String qualifier = txAttr != null ? txAttr.getQualifier() : null;
// Do not attempt to lookup tx manager if no tx attributes are set
if (txAttr == null || this.beanFactory == null) {
return getTransactionManager();
}
String qualifier = (txAttr.getQualifier() != null ?
txAttr.getQualifier() : this.transactionManagerBeanName);
if (StringUtils.hasText(qualifier)) {
return determineQualifiedTransactionManager(qualifier);
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
if (txManager == null) {
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, PlatformTransactionManager.class, qualifier);
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
}
else if (StringUtils.hasText(this.transactionManagerBeanName)) {
return determineQualifiedTransactionManager(this.transactionManagerBeanName);
return txManager;
}
else if (txAttr != null) { // Do not lookup default bean name if no tx attributes are set
else {
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
if (defaultTransactionManager == null) {
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
@ -367,18 +374,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init @@ -367,18 +374,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
return defaultTransactionManager;
}
}
return getTransactionManager();
}
private PlatformTransactionManager determineQualifiedTransactionManager(String qualifier) {
PlatformTransactionManager txManager = this.transactionManagerCache.get(qualifier);
if (txManager == null) {
txManager = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, PlatformTransactionManager.class, qualifier);
this.transactionManagerCache.putIfAbsent(qualifier, txManager);
}
return txManager;
}
/**
* Convenience method to return a String representation of this Method

Loading…
Cancel
Save