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 String transactionManagerBeanName;
|
||||||
|
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
private TransactionAttributeSource transactionAttributeSource;
|
private TransactionAttributeSource transactionAttributeSource;
|
||||||
|
|
||||||
private BeanFactory beanFactory;
|
private BeanFactory beanFactory;
|
||||||
|
@ -158,16 +160,14 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
* @see #setTransactionManagerBeanName
|
* @see #setTransactionManagerBeanName
|
||||||
*/
|
*/
|
||||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||||
if (transactionManager != null) {
|
this.transactionManager = transactionManager;
|
||||||
this.transactionManagerCache.put(DEFAULT_TRANSACTION_MANAGER_KEY, transactionManager);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the default transaction manager, or {@code null} if unknown.
|
* Return the default transaction manager, or {@code null} if unknown.
|
||||||
*/
|
*/
|
||||||
public PlatformTransactionManager getTransactionManager() {
|
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
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
if (getTransactionManager() == null && this.beanFactory == null) {
|
if (getTransactionManager() == null && getBeanFactory() == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Setting the property 'transactionManager' or running in a BeanFactory is required");
|
"Setting the property 'transactionManager' or running in a BeanFactory is required");
|
||||||
}
|
}
|
||||||
if (this.transactionAttributeSource == null) {
|
if (getTransactionAttributeSource() == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Either 'transactionAttributeSource' or 'transactionAttributes' is required: " +
|
"Either 'transactionAttributeSource' or 'transactionAttributes' is required: " +
|
||||||
"If there are no transactional methods, then don't use a transaction aspect.");
|
"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 {
|
else {
|
||||||
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
|
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
|
||||||
if (defaultTransactionManager == null) {
|
if (defaultTransactionManager == null) {
|
||||||
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
defaultTransactionManager = this.transactionManagerCache.get(DEFAULT_TRANSACTION_MANAGER_KEY);
|
||||||
this.transactionManagerCache.putIfAbsent(
|
if (defaultTransactionManager == null) {
|
||||||
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
|
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
|
||||||
|
this.transactionManagerCache.putIfAbsent(
|
||||||
|
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return defaultTransactionManager;
|
return defaultTransactionManager;
|
||||||
}
|
}
|
||||||
|
@ -567,6 +570,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||||
|
|
||||||
public TransactionInfo(PlatformTransactionManager transactionManager,
|
public TransactionInfo(PlatformTransactionManager transactionManager,
|
||||||
TransactionAttribute transactionAttribute, String joinpointIdentification) {
|
TransactionAttribute transactionAttribute, String joinpointIdentification) {
|
||||||
|
|
||||||
this.transactionManager = transactionManager;
|
this.transactionManager = transactionManager;
|
||||||
this.transactionAttribute = transactionAttribute;
|
this.transactionAttribute = transactionAttribute;
|
||||||
this.joinpointIdentification = joinpointIdentification;
|
this.joinpointIdentification = joinpointIdentification;
|
||||||
|
|
Loading…
Reference in New Issue