Skip to content

Commit fd7153f

Browse files
committed
Do not retain cache transaction managers
Previously, cache transaction managers may be retained outside the boundaries of an application context with AspectJ since an aspect is basically a singleton for the current class loader. This commit adds a "clearTransactionManagerCache" that is similar to the "clearMetadataCache" introduced in CacheAspectSupport: whenever the context is disposed, the cache is cleared to remove any reference to a transaction manager defined by that context. Issue: SPR-12518
1 parent cec26e9 commit fd7153f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spring-aspects/src/main/java/org/springframework/transaction/aspectj/AbstractTransactionAspect.aj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.springframework.transaction.aspectj;
1919
import org.aspectj.lang.annotation.SuppressAjWarnings;
2020
import org.aspectj.lang.reflect.MethodSignature;
2121

22+
import org.springframework.beans.factory.DisposableBean;
2223
import org.springframework.transaction.interceptor.TransactionAspectSupport;
2324
import org.springframework.transaction.interceptor.TransactionAttributeSource;
2425

@@ -44,7 +45,7 @@ import org.springframework.transaction.interceptor.TransactionAttributeSource;
4445
* @author Juergen Hoeller
4546
* @since 2.0
4647
*/
47-
public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport {
48+
public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport implements DisposableBean {
4849

4950
/**
5051
* Construct the aspect using the given transaction metadata retrieval strategy.
@@ -56,6 +57,11 @@ public abstract aspect AbstractTransactionAspect extends TransactionAspectSuppor
5657
setTransactionAttributeSource(tas);
5758
}
5859

60+
@Override
61+
public void destroy() {
62+
clearTransactionManagerCache(); // An aspect is basically a singleton
63+
}
64+
5965
@SuppressAjWarnings("adviceDidNotMatch")
6066
Object around(final Object txObject): transactionalMethodExecution(txObject) {
6167
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ public Object doInTransaction(TransactionStatus status) {
338338
}
339339
}
340340

341+
/**
342+
* Clear the cached transaction managers.
343+
*/
344+
protected void clearTransactionManagerCache() {
345+
this.transactionManagerCache.clear();
346+
}
347+
341348
/**
342349
* Determine the specific transaction manager to use for the given transaction.
343350
*/

0 commit comments

Comments
 (0)