这是我能够执行此操作的方式-
@Overridepublic void initialize(FieldMatch constraintAnnotation){ firstFieldName = constraintAnnotation.first(); secondFieldName = constraintAnnotation.second(); thirdFieldName = constraintAnnotation.third(); match = constraintAnnotation.match(); //set a message variable on initialization if("true".equals(match)){ message = constraintAnnotation.message(); } else{ message = "{password.error.threeQuestionsSameAnswer}";}}@Overridepublic boolean isValid(final Object value, final ConstraintValidatorContext context){ Object firstObj = null; Object secondObj = null; Object thirdObj = null; //disable existing violation message context.disableDefaultConstraintViolation(); //build new violation message and add it context.buildConstraintViolationWithTemplate(message).addConstraintViolation();etc.........}


