Skip to content

Commit

Permalink
Do not retain cache transaction managers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
snicoll committed Dec 16, 2014
1 parent cec26e9 commit fd7153f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.springframework.transaction.aspectj;
import org.aspectj.lang.annotation.SuppressAjWarnings;
import org.aspectj.lang.reflect.MethodSignature;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.transaction.interceptor.TransactionAttributeSource;

Expand All @@ -44,7 +45,7 @@ import org.springframework.transaction.interceptor.TransactionAttributeSource;
* @author Juergen Hoeller
* @since 2.0
*/
public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport {
public abstract aspect AbstractTransactionAspect extends TransactionAspectSupport implements DisposableBean {

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

@Override
public void destroy() {
clearTransactionManagerCache(); // An aspect is basically a singleton
}

@SuppressAjWarnings("adviceDidNotMatch")
Object around(final Object txObject): transactionalMethodExecution(txObject) {
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ public Object doInTransaction(TransactionStatus status) {
}
}

/**
* Clear the cached transaction managers.
*/
protected void clearTransactionManagerCache() {
this.transactionManagerCache.clear();
}

/**
* Determine the specific transaction manager to use for the given transaction.
*/
Expand Down

0 comments on commit fd7153f

Please sign in to comment.