在请求POJO上使用自定义验证批注时,它没有执行约束所要求的检查。
当我直接从控制器调用验证器时,它将起作用。软件包处于组件扫描状态,因为同一软件包中的其他类是在春季注入的。
@Documented
@Constraint(validatedBy = Validator.class)
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface ValidRequest{
String message() default "";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
}
@Component
public class Validator implements ConstraintValidator<ValidRequest,Request>
{
@Override
public void initialize(ValidRequest valid) {
}
@Override
public boolean isValid(){
//validation logic here
}
}
//Annotation applied on request object
@ValidRequest
public class Request{
}
I expect isValidMethod should be called when I receive the Request in controller. It's not getting called.