提交 fd7153ff 编写于 作者: S Stephane Nicoll

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
上级 cec26e9a
......@@ -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;
......@@ -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.
......@@ -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();
......
......@@ -338,6 +338,13 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
}
}
/**
* Clear the cached transaction managers.
*/
protected void clearTransactionManagerCache() {
this.transactionManagerCache.clear();
}
/**
* Determine the specific transaction manager to use for the given transaction.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册