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
This commit is contained in:
parent
cec26e9ac4
commit
fd7153ffbb
|
@ -19,6 +19,7 @@ package org.springframework.transaction.aspectj;
|
||||||
import org.aspectj.lang.annotation.SuppressAjWarnings;
|
import org.aspectj.lang.annotation.SuppressAjWarnings;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.0
|
* @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.
|
* Construct the aspect using the given transaction metadata retrieval strategy.
|
||||||
|
@ -56,6 +57,11 @@ public abstract aspect AbstractTransactionAspect extends TransactionAspectSuppor
|
||||||
setTransactionAttributeSource(tas);
|
setTransactionAttributeSource(tas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
clearTransactionManagerCache(); // An aspect is basically a singleton
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressAjWarnings("adviceDidNotMatch")
|
@SuppressAjWarnings("adviceDidNotMatch")
|
||||||
Object around(final Object txObject): transactionalMethodExecution(txObject) {
|
Object around(final Object txObject): transactionalMethodExecution(txObject) {
|
||||||
MethodSignature methodSignature = (MethodSignature) thisJoinPoint.getSignature();
|
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.
|
* Determine the specific transaction manager to use for the given transaction.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue