Search in sources :

Example 1 with BeanExpressionException

use of org.springframework.beans.factory.BeanExpressionException in project spring-framework by spring-projects.

the class StandardBeanExpressionResolver method evaluate.

@Override
public Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException {
    if (!StringUtils.hasLength(value)) {
        return value;
    }
    try {
        Expression expr = this.expressionCache.get(value);
        if (expr == null) {
            expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
            this.expressionCache.put(value, expr);
        }
        StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
        if (sec == null) {
            sec = new StandardEvaluationContext();
            sec.setRootObject(evalContext);
            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()));
            ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
            if (conversionService != null) {
                sec.setTypeConverter(new StandardTypeConverter(conversionService));
            }
            customizeEvaluationContext(sec);
            this.evaluationCache.put(evalContext, sec);
        }
        return expr.getValue(sec);
    } catch (Exception ex) {
        throw new BeanExpressionException("Expression parsing failed", ex);
    }
}
Also used : StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) BeanExpressionException(org.springframework.beans.factory.BeanExpressionException) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) Expression(org.springframework.expression.Expression) ConversionService(org.springframework.core.convert.ConversionService) BeanExpressionException(org.springframework.beans.factory.BeanExpressionException) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)1 BeanExpressionException (org.springframework.beans.factory.BeanExpressionException)1 ConversionService (org.springframework.core.convert.ConversionService)1 Expression (org.springframework.expression.Expression)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1 StandardTypeConverter (org.springframework.expression.spel.support.StandardTypeConverter)1 StandardTypeLocator (org.springframework.expression.spel.support.StandardTypeLocator)1