クラス SimpleEvaluationContext

java.lang.ObjectSE
org.springframework.expression.spel.support.SimpleEvaluationContext
実装済みのインターフェース一覧:
EvaluationContext

public final class SimpleEvaluationContext extends ObjectSE implements EvaluationContext
基本的な SpEL 機能とカスタマイズオプションのサブセットに焦点を当てた EvaluationContext の基本的な実装で、単純な条件評価と特定のデータバインディングシナリオを対象としています。

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 — for example, excluding references to Java types, constructors, and bean references.

SimpleEvaluationContext を作成するときは、SpEL 式でのデータバインディングに必要なサポートレベルを選択する必要があります。

  • 読み取り専用アクセスのデータバインディング
  • 読み取りおよび書き込みアクセスのデータバインディング
  • カスタム PropertyAccessor (通常、反射ベースではない)、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(PropertyAccessor...), consider disabling assignment (recommended), and optionally activate method resolution and/or a type converter through the builder.

SimpleEvaluationContext は通常、デフォルトのルートオブジェクトで構成されていないことに注意してください。代わりに、一度作成され、EvaluationContext とルートオブジェクトの両方を引数として持つ定義済み Expression に対する getValue 呼び出しを通じて繰り返し使用されることを目的としています: Expression.getValue(EvaluationContext, Object)

EvaluationContext API で定義されている変数の設定と検索のサポートに加え、SimpleEvaluationContext は関数を変数として登録および検索することもサポートします。この評価コンテキストでは関数は変数と共通の名前空間を共有するため、関数名と変数名が重複しないように注意する必要があります。

パワーと柔軟性を高めるため、特に内部構成のシナリオでは、代わりに StandardEvaluationContext の使用を検討してください。

WARNING: Although SimpleEvaluationContext restricts the SpEL language to a subset of its features, that restriction is provided on a best-effort basis and does not guarantee that evaluation of an expression is safe; SimpleEvaluationContext must not be considered safe for evaluating a SpEL expression obtained from an untrusted source. This responsibility extends to property accessors: restricting a SimpleEvaluationContext to read-only data binding governs only whether assignment to a property is permitted and does not verify that reading a property is free of side effects. See the セキュリティに関する考慮事項 and Object Design sections of the Spring Framework reference documentation, as well as the class-level documentation for ReflectivePropertyAccessor and DataBindingPropertyAccessor, for details.

Because a parsed Expression may cache accessor and executor state resolved against a particular EvaluationContext configuration, a parsed Expression must never be evaluated first against a StandardEvaluationContext (or any other, less restrictive, EvaluationContext) and later against a SimpleEvaluationContext. If the same expression string must be evaluated under both kinds of contexts, parse it into two distinct Expression instances instead. See Expression for further details on this lifecycle contract.

導入:
4.3.15
作成者:
Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
関連事項: