title: Cannot override ConstraintValidator default message in Spring-MVC
body: <p>I am having issues with overriding the default ConstraintValidator message when using Spring validation.</p>
  
  <p>I have a custom messages.properties file that contains the following values:</p>
  
  <pre><code>NotNull=This field is mandatory
  BankHoliday=You cannot select a bank holiday
  </code></pre>
  
  <p>My annotation for BankHoliday is as follows:</p>
  
  <pre><code>@Documented
  @Constraint(validatedBy = BankHolidayValidator.class)
  @Target(ElementType.FIELD)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface BankHoliday {
  
      String message() default "{BankHoliday}";
  
      Class&lt;?&gt;[] groups() default {};
  
      Class&lt;? extends Payload&gt;[] payload() default {};
  }
  </code></pre>
  
  <p>My validator is as follows:</p>
  
  <pre><code>public class BankHolidayValidator implements ConstraintValidator&lt;BankHoliday, Date&gt; {
  
  @Override
  public void initialize(BankHoliday bankHoliday) { }
  
  @Override
  public boolean isValid(Date date, ConstraintValidatorContext cxt) {
  
      if(date == null) {
          cxt.disableDefaultConstraintViolation();
          cxt.buildConstraintViolationWithTemplate("{NotNull}").addConstraintViolation();
          return false;
      } else if (isBankHoliday(date)) {
          return false;
      } else {
          return true;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My model is annotated with the @BankHoliday annotation:</p>
  
  <pre><code>@BankHoliday
  @DateTimeFormat(pattern = "dd/MM/yy")
  private Date desiredBookingDate;
  </code></pre>
  
  <p>My controller looks like:</p>
  
  <pre><code>@RequestMapping(value="/new/request", method = RequestMethod.POST)
  public String putNewRequest(@Valid @ModelAttribute("request") Request request, BindingResult bindingResult, Map&lt;String, Object&gt; map) {
  
      if (bindingResult.hasErrors()) {
  
          // return them back
  
      } else {
  
          // process the request
      }
  }
  </code></pre>
  
  <p>However, when the user does not populate this field, the error message they see is "You cannot select a bank holiday" instead of "This field is mandatory". Having stepped through the code I can see that the cxt.disableDefaultConstraintViolation() line is definitely being called and the {NotNull} constraint validation is being added, but the user always sees the default message.</p>
  
  <p>I have tried replacing "{NotNull}" with "A test message" and this does not work either. Can anyone point me in the right direction as to why this isn't working?</p>