public class MethodValidationInterceptor extends ObjectSE implements MethodInterceptor
MethodInterceptor
実装。該当するメソッドには、パラメーターおよび / または戻り値に JSR-303 制約アノテーションがあります(後者の場合、メソッドレベルで、通常はインラインアノテーションとして指定されます)。
E.g .: public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2)
検証グループは、Spring の Validated
アノテーションを通じて、それを含むターゲットクラスの型レベルで指定でき、そのクラスのすべてのパブリックサービスメソッドに適用されます。デフォルトでは、JSR-303 はデフォルトグループに対してのみ検証します。
Spring 5.0 の時点で、この機能には Bean 検証 1.1 + プロバイダーが必要です。
MethodValidationPostProcessor
, ExecutableValidator
EEコンストラクターと説明 |
---|
MethodValidationInterceptor() 下にあるデフォルトの JSR-303 バリデーターを使用して、新しい MethodValidationInterceptor を作成します。 |
MethodValidationInterceptor(ValidatorEE validator) 指定された JSR-303 バリデーターを使用して、新しい MethodValidationInterceptor を作成します。 |
MethodValidationInterceptor(ValidatorFactoryEE validatorFactory) 指定された JSR-303 ValidatorFactory を使用して新しい MethodValidationInterceptor を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected ClassSE<?>[] | determineValidationGroups(MethodInvocation invocation) 特定のメソッド呼び出しに対して検証する検証グループを決定します。 |
ObjectSE | invoke(MethodInvocation invocation) このメソッドを実装して、呼び出しの前後に追加の処理を実行します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public MethodValidationInterceptor()
public MethodValidationInterceptor(ValidatorFactoryEE validatorFactory)
validatorFactory
- 使用する JSR-303 ValidatorFactorypublic MethodValidationInterceptor(ValidatorEE validator)
validator
- 使用する JSR-303 バリデーター public ObjectSE invoke(MethodInvocation invocation) throws ThrowableSE
MethodInterceptor
Joinpoint.proceed()
を呼び出すようにします。MethodInterceptor
の invoke
invocation
- メソッド呼び出しジョインポイント Joinpoint.proceed()
の呼び出しの結果。インターセプターによってインターセプトされる可能性があります ThrowableSE
- インターセプターまたはターゲットオブジェクトが例外をスローする場合 protected ClassSE<?>[] determineValidationGroups(MethodInvocation invocation)
デフォルトは、メソッドの含まれているターゲットクラスの Validated
アノテーションで指定されている検証グループです。
invocation
- 現在の MethodInvocation