Class SimpleEvaluationContext
- All Implemented Interfaces:
- EvaluationContext
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 property access in SpEL expressions:
 
- A custom PropertyAccessor(typically not reflection-based), potentially combined with aDataBindingPropertyAccessor
- Data binding properties for read-only access
- Data binding properties for read and write
Conveniently, forReadOnlyDataBinding()
 enables read access to properties via DataBindingPropertyAccessor;
 same for forReadWriteDataBinding() when
 write access is needed as well. Alternatively, configure custom accessors
 via forPropertyAccessors(org.springframework.expression.PropertyAccessor...), and potentially
 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 pre-compiled
 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:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classBuilder forSimpleEvaluationContext.
- 
Method SummaryModifier and TypeMethodDescriptionassignVariable(String name, Supplier<TypedValue> valueSupplier) SimpleEvaluationContextdoes not support variable assignment within expressions.forPropertyAccessors(PropertyAccessor... accessors) Create aSimpleEvaluationContextfor the specifiedPropertyAccessordelegates: typically a customPropertyAccessorspecific to a use case (e.g.Create aSimpleEvaluationContextfor read-only access to public properties viaDataBindingPropertyAccessor.Create aSimpleEvaluationContextfor read-write access to public properties viaDataBindingPropertyAccessor.SimpleEvaluationContextdoes not support the use of bean references.Return an empty list, always, since this context does not support the use of type references.Return the specifiedMethodResolverdelegates, if any.Return an instance ofStandardOperatorOverloader.Return the specifiedPropertyAccessordelegates, if any.Return the specified root object, if any.Return an instance ofStandardTypeComparator.The configuredTypeConverter.SimpleEvaluationContextdoes not support use of type references.lookupVariable(String name) Look up a named variable within this evaluation context.voidsetVariable(String name, Object value) Set a named variable in this evaluation context to a specified value.
- 
Method Details- 
getRootObjectReturn the specified root object, if any.- Specified by:
- getRootObjectin interface- EvaluationContext
 
- 
getPropertyAccessorsReturn the specifiedPropertyAccessordelegates, if any.- Specified by:
- getPropertyAccessorsin interface- EvaluationContext
- See Also:
 
- 
getConstructorResolversReturn an empty list, always, since this context does not support the use of type references.- Specified by:
- getConstructorResolversin interface- EvaluationContext
 
- 
getMethodResolversReturn the specifiedMethodResolverdelegates, if any.- Specified by:
- getMethodResolversin interface- EvaluationContext
- See Also:
 
- 
getBeanResolverSimpleEvaluationContextdoes not support the use of bean references.- Specified by:
- getBeanResolverin interface- EvaluationContext
- Returns:
- always null
 
- 
getTypeLocatorSimpleEvaluationContextdoes not support use of type references.- Specified by:
- getTypeLocatorin interface- EvaluationContext
- Returns:
- TypeLocatorimplementation that raises a- SpelEvaluationExceptionwith- SpelMessage.TYPE_NOT_FOUND.
 
- 
getTypeConverterThe configuredTypeConverter.By default this is StandardTypeConverter.
- 
getTypeComparatorReturn an instance ofStandardTypeComparator.- Specified by:
- getTypeComparatorin interface- EvaluationContext
 
- 
getOperatorOverloaderReturn an instance ofStandardOperatorOverloader.- Specified by:
- getOperatorOverloaderin interface- EvaluationContext
 
- 
assignVariableSimpleEvaluationContextdoes not support variable assignment within expressions.- Specified by:
- assignVariablein interface- EvaluationContext
- Parameters:
- name- the name of the variable to assign
- valueSupplier- the supplier of the value to be assigned to the variable
- Returns:
- a TypedValuewrapping the assigned value
- Throws:
- SpelEvaluationException- with- SpelMessage.VARIABLE_ASSIGNMENT_NOT_SUPPORTED
- Since:
- 5.2.24
 
- 
setVariableDescription copied from interface:EvaluationContextSet a named variable in this evaluation context to a specified value.In contrast to EvaluationContext.assignVariable(String, Supplier), this method should only be invoked programmatically when interacting directly with theEvaluationContext— for example, to provide initial configuration for the context.- Specified by:
- setVariablein interface- EvaluationContext
- Parameters:
- name- the name of the variable to set
- value- the value to be placed in the variable
 
- 
lookupVariableDescription copied from interface:EvaluationContextLook up a named variable within this evaluation context.- Specified by:
- lookupVariablein interface- EvaluationContext
- Parameters:
- name- the name of the variable to look up
- Returns:
- the value of the variable, or nullif not found
 
- 
forPropertyAccessorsCreate aSimpleEvaluationContextfor the specifiedPropertyAccessordelegates: typically a customPropertyAccessorspecific to a use case (e.g. attribute resolution in a custom data structure), potentially combined with aDataBindingPropertyAccessorif property dereferences are needed as well.- Parameters:
- accessors- the accessor delegates to use
- See Also:
 
- 
forReadOnlyDataBindingCreate aSimpleEvaluationContextfor read-only access to public properties viaDataBindingPropertyAccessor.
- 
forReadWriteDataBindingCreate aSimpleEvaluationContextfor read-write access to public properties viaDataBindingPropertyAccessor.
 
-