Spring Boot JSR303 message code in annotation getting ignored

前端 未结 2 891
生来不讨喜
生来不讨喜 2020-12-18 00:39

In my Spring Boot app I have a backing bean where I am using JSR303 validation. In the annotation, I have specified the message code:

@NotBlank(message = \"         


        
2条回答
  •  感情败类
    2020-12-18 01:28

    According to JSR-303 specification message parameters are expected to be stored in ValidationMessages.properties files. But you can override the place where they are looked for.

    So you have 2 options:

    1. Move your messages to the ValidationMessages.properties file
    2. Or override getValidator() method of your WebMvcConfigurerAdapter's descendant (JavaConfig in your case):

      @Override
      public Validator getValidator() {
          LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
          validator.setValidationMessageSource(messageSource());
          return validator;
      }
      

提交回复
热议问题