Skip to content

Commit 951ac5e

Browse files
committed
TransactionAspectSupport stores given PlatformTransactionManager instance as strong reference
Issue: SPR-14609
1 parent 3d297b1 commit 951ac5e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public static TransactionStatus currentTransactionStatus() throws NoTransactionE
128128

129129
private String transactionManagerBeanName;
130130

131+
private PlatformTransactionManager transactionManager;
132+
131133
private TransactionAttributeSource transactionAttributeSource;
132134

133135
private BeanFactory beanFactory;
@@ -158,16 +160,14 @@ protected final String getTransactionManagerBeanName() {
158160
* @see #setTransactionManagerBeanName
159161
*/
160162
public void setTransactionManager(PlatformTransactionManager transactionManager) {
161-
if (transactionManager != null) {
162-
this.transactionManagerCache.put(DEFAULT_TRANSACTION_MANAGER_KEY, transactionManager);
163-
}
163+
this.transactionManager = transactionManager;
164164
}
165165

166166
/**
167167
* Return the default transaction manager, or {@code null} if unknown.
168168
*/
169169
public PlatformTransactionManager getTransactionManager() {
170-
return this.transactionManagerCache.get(DEFAULT_TRANSACTION_MANAGER_KEY);
170+
return this.transactionManager;
171171
}
172172

173173
/**
@@ -240,11 +240,11 @@ protected final BeanFactory getBeanFactory() {
240240
*/
241241
@Override
242242
public void afterPropertiesSet() {
243-
if (getTransactionManager() == null && this.beanFactory == null) {
243+
if (getTransactionManager() == null && getBeanFactory() == null) {
244244
throw new IllegalStateException(
245245
"Setting the property 'transactionManager' or running in a BeanFactory is required");
246246
}
247-
if (this.transactionAttributeSource == null) {
247+
if (getTransactionAttributeSource() == null) {
248248
throw new IllegalStateException(
249249
"Either 'transactionAttributeSource' or 'transactionAttributes' is required: " +
250250
"If there are no transactional methods, then don't use a transaction aspect.");
@@ -363,9 +363,12 @@ else if (StringUtils.hasText(this.transactionManagerBeanName)) {
363363
else {
364364
PlatformTransactionManager defaultTransactionManager = getTransactionManager();
365365
if (defaultTransactionManager == null) {
366-
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
367-
this.transactionManagerCache.putIfAbsent(
368-
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
366+
defaultTransactionManager = this.transactionManagerCache.get(DEFAULT_TRANSACTION_MANAGER_KEY);
367+
if (defaultTransactionManager == null) {
368+
defaultTransactionManager = this.beanFactory.getBean(PlatformTransactionManager.class);
369+
this.transactionManagerCache.putIfAbsent(
370+
DEFAULT_TRANSACTION_MANAGER_KEY, defaultTransactionManager);
371+
}
369372
}
370373
return defaultTransactionManager;
371374
}
@@ -567,6 +570,7 @@ protected final class TransactionInfo {
567570

568571
public TransactionInfo(PlatformTransactionManager transactionManager,
569572
TransactionAttribute transactionAttribute, String joinpointIdentification) {
573+
570574
this.transactionManager = transactionManager;
571575
this.transactionAttribute = transactionAttribute;
572576
this.joinpointIdentification = joinpointIdentification;

0 commit comments

Comments
 (0)