Merge branch '5.3.x'

This commit is contained in:
Sam Brannen 2022-03-21 17:13:30 +01:00
commit d11389e783
2 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,8 +20,8 @@ import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
/**
* Strategy interface for resolving a value through evaluating it
* as an expression, if applicable.
* Strategy interface for resolving a value by evaluating it as an expression,
* if applicable.
*
* <p>A raw {@link org.springframework.beans.factory.BeanFactory} does not
* contain a default implementation of this strategy. However,
@ -36,12 +36,13 @@ public interface BeanExpressionResolver {
/**
* Evaluate the given value as an expression, if applicable;
* return the value as-is otherwise.
* @param value the value to check
* @param evalContext the evaluation context
* @param value the value to evaluate as an expression
* @param beanExpressionContext the bean expression context to use when
* evaluating the expression
* @return the resolved value (potentially the given value as-is)
* @throws BeansException if evaluation failed
*/
@Nullable
Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException;
}

View File

@ -138,7 +138,7 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver {
@Override
@Nullable
public Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException {
public Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException {
if (!StringUtils.hasLength(value)) {
return value;
}
@ -148,21 +148,21 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver {
expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
this.expressionCache.put(value, expr);
}
StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
StandardEvaluationContext sec = this.evaluationCache.get(beanExpressionContext);
if (sec == null) {
sec = new StandardEvaluationContext(evalContext);
sec = new StandardEvaluationContext(beanExpressionContext);
sec.addPropertyAccessor(new BeanExpressionContextAccessor());
sec.addPropertyAccessor(new BeanFactoryAccessor());
sec.addPropertyAccessor(new MapAccessor());
sec.addPropertyAccessor(new EnvironmentAccessor());
sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
sec.setBeanResolver(new BeanFactoryResolver(beanExpressionContext.getBeanFactory()));
sec.setTypeLocator(new StandardTypeLocator(beanExpressionContext.getBeanFactory().getBeanClassLoader()));
sec.setTypeConverter(new StandardTypeConverter(() -> {
ConversionService cs = evalContext.getBeanFactory().getConversionService();
ConversionService cs = beanExpressionContext.getBeanFactory().getConversionService();
return (cs != null ? cs : DefaultConversionService.getSharedInstance());
}));
customizeEvaluationContext(sec);
this.evaluationCache.put(evalContext, sec);
this.evaluationCache.put(beanExpressionContext, sec);
}
return expr.getValue(sec);
}