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 = \"
JSR303 interpolation normally works with ValidationMessages.properties
file. However you can configure Spring to change that if you want (I was lazy to do so :)) e.g.
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource" />
</bean>
<mvc:annotation-driven validator="validator" />
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:
ValidationMessages.properties
fileOr 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;
}