TransactionAspectSupport stores given PlatformTransactionManager instance as strong reference
Issue: SPR-14609
This commit is contained in:
parent
3d297b10e9
commit
951ac5ea4f
|
@ -128,6 +128,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
|
||||
private String transactionManagerBeanName;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private TransactionAttributeSource transactionAttributeSource;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
@ -158,16 +160,14 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
* @see #setTransactionManagerBeanName
|
||||
*/
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
if (transactionManager != null) {
|
||||
this.transactionManagerCache.put(DEFAULT_TRANSACTION_MANAGER_KEY, transactionManager);
|
||||
}
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default transaction manager, or {@code null} if unknown.
|
||||
*/
|
||||
public PlatformTransactionManager getTransactionManager() {
|
||||
return this.transactionManagerCache.get(DEFAULT_TRANSACTION_MANAGER_KEY);
|
||||
return this.transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,11 +240,11 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (getTransactionManager() == null && this.beanFactory == null) {
|
||||
if (getTransactionManager() == null && getBeanFactory() == null) {
|
||||
throw new IllegalStateException(
|
||||
"Setting the property 'transactionManager' or running in a BeanFactory is required");
|
||||
}
|
||||
if (this.transactionAttributeSource == null) {
|
||||
if (getTransactionAttributeSource() == null) {
|
||||
throw new IllegalStateException(
|
||||
"Either 'transactionAttributeSource' or 'transactionAttributes' is required: " +
|
||||
"If there are no transactional methods, then don't use a transaction aspect.");
|
||||
|
@ -363,9 +363,12 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
else {
|
||||
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
|
||||
if (defaultTransactionManager == null) {
|
||||
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
||||
this.transactionManagerCache.putIfAbsent(
|
||||
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
|
||||
defaultTransactionManager = this.transactionManagerCache.get(DEFAULT_TRANSACTION_MANAGER_KEY);
|
||||
if (defaultTransactionManager == null) {
|
||||
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
||||
this.transactionManagerCache.putIfAbsent(
|
||||
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
|
||||
}
|
||||
}
|
||||
return defaultTransactionManager;
|
||||
}
|
||||
|
@ -567,6 +570,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
|
||||
public TransactionInfo(PlatformTransactionManager transactionManager,
|
||||
TransactionAttribute transactionAttribute, String joinpointIdentification) {
|
||||
|
||||
this.transactionManager = transactionManager;
|
||||
this.transactionAttribute = transactionAttribute;
|
||||
this.joinpointIdentification = joinpointIdentification;
|
||||
|
|
Loading…
Reference in New Issue