Support for bean refs in caching SpEL expressions

Issue: SPR-13182
This commit is contained in:
Stephane Nicoll
2015-12-22 11:05:24 +01:00
parent 1ce9788a66
commit 9b5e47026c
4 changed files with 103 additions and 21 deletions

View File

@@ -705,7 +705,8 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private EvaluationContext createEvaluationContext(Object result) {
return evaluator.createEvaluationContext(
this.caches, this.metadata.method, this.args, this.target, this.metadata.targetClass, result);
this.caches, this.metadata.method, this.args, this.target, this.metadata.targetClass,
result, applicationContext);
}
protected Collection<? extends Cache> getCaches() {

View File

@@ -22,8 +22,10 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.cache.Cache;
import org.springframework.context.expression.AnnotatedElementKey;
import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.CachedExpressionEvaluator;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
@@ -75,12 +77,12 @@ class ExpressionEvaluator extends CachedExpressionEvaluator {
/**
* Create an {@link EvaluationContext} without a return value.
* @see #createEvaluationContext(Collection, Method, Object[], Object, Class, Object)
* @see #createEvaluationContext(Collection, Method, Object[], Object, Class, Object, BeanFactory)
*/
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches,
Method method, Object[] args, Object target, Class<?> targetClass) {
Method method, Object[] args, Object target, Class<?> targetClass, BeanFactory beanFactory) {
return createEvaluationContext(caches, method, args, target, targetClass, NO_RESULT);
return createEvaluationContext(caches, method, args, target, targetClass, NO_RESULT, beanFactory);
}
/**
@@ -95,7 +97,8 @@ class ExpressionEvaluator extends CachedExpressionEvaluator {
* @return the evaluation context
*/
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches,
Method method, Object[] args, Object target, Class<?> targetClass, Object result) {
Method method, Object[] args, Object target, Class<?> targetClass, Object result,
BeanFactory beanFactory) {
CacheExpressionRootObject rootObject = new CacheExpressionRootObject(caches,
method, args, target, targetClass);
@@ -108,6 +111,9 @@ class ExpressionEvaluator extends CachedExpressionEvaluator {
else if (result != NO_RESULT) {
evaluationContext.setVariable(RESULT_VARIABLE, result);
}
if (beanFactory != null) {
evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
}
return evaluationContext;
}