Class SimpleEvaluationContext

java.lang.Object
org.springframework.expression.spel.support.SimpleEvaluationContext
All Implemented Interfaces:
EvaluationContext

public final class SimpleEvaluationContext extends Object implements EvaluationContext
A basic implementation of EvaluationContext that focuses on a subset of essential SpEL features and customization options, targeting simple condition evaluation and in particular data binding scenarios.

In many cases, the full extent of the SpEL language is not required and should be meaningfully restricted. Examples include but are not limited to data binding expressions, property-based filters, and others. To that effect, SimpleEvaluationContext is tailored to support only a subset of the SpEL language syntax, e.g. excluding references to Java types, constructors, and bean references.

When creating a SimpleEvaluationContext you need to choose the level of support that you need for data binding in SpEL expressions:

  • Data binding for read-only access
  • Data binding for read and write access
  • A custom PropertyAccessor (typically not reflection-based), potentially combined with a DataBindingPropertyAccessor

Conveniently, forReadOnlyDataBinding() enables read-only access to properties via DataBindingPropertyAccessor. Similarly, forReadWriteDataBinding() enables read and write access to properties. Alternatively, configure custom accessors via forPropertyAccessors(org.springframework.expression.PropertyAccessor...), potentially disable assignment, and optionally activate method resolution and/or a type converter through the builder.

Note that SimpleEvaluationContext is typically not configured with a default root object. Instead it is meant to be created once and used repeatedly through getValue calls on a predefined Expression with both an EvaluationContext and a root object as arguments: Expression.getValue(EvaluationContext, Object).

For more power and flexibility, in particular for internal configuration scenarios, consider using StandardEvaluationContext instead.

Since:
4.3.15
Author:
Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
See Also: