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
This commit is contained in:
parent
4a0ac97550
commit
961574bd17
|
@ -349,15 +349,22 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
* Determine the specific transaction manager to use for the given transaction.
|
* Determine the specific transaction manager to use for the given transaction.
|
||||||
*/
|
*/
|
||||||
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
|
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
|
||||||
if (this.beanFactory != null) {
|
// Do not attempt to lookup tx manager if no tx attributes are set
|
||||||
String qualifier = txAttr != null ? txAttr.getQualifier() : null;
|
if (txAttr == null || this.beanFactory == null) {
|
||||||
|
return getTransactionManager();
|
||||||
|
}
|
||||||
|
String qualifier = (txAttr.getQualifier() != null ?
|
||||||
|
txAttr.getQualifier() : this.transactionManagerBeanName);
|
||||||
if (StringUtils.hasText(qualifier)) {
|
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 txManager;
|
||||||
return determineQualifiedTransactionManager(this.transactionManagerBeanName);
|
|
||||||
}
|
}
|
||||||
else if (txAttr != null) { // Do not lookup default bean name if no tx attributes are set
|
else {
|
||||||
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
|
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
|
||||||
if (defaultTransactionManager == null) {
|
if (defaultTransactionManager == null) {
|
||||||
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
||||||
|
@ -367,18 +374,6 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
return defaultTransactionManager;
|
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
|
* Convenience method to return a String representation of this Method
|
||||||
|
|
Loading…
Reference in New Issue