有没有办法从Bean Validation字段级ConstraintValidator中访问目标bean?

时间:2014-11-19 01:11:22

标签: java validation bean-validation nhibernate-validator

除了使用类级验证之外,有没有办法从验证器类中访问字段级验证注释的父bean?

例如:

public class CustomValidator implements ConstraintValidator<CustomValidation, String> {

    @Override
    public void initialize(final CustomValidation constraintAnnotation) {
    }

    @Override
    public boolean isValid(final String fieldValue, final ConstraintValidatorContext context) {
        // is there a way to access the parent object here?
    }
}

1 个答案:

答案 0 :(得分:2)

经过进一步调查,结果证明这不适用于规范1.1版。