I’m trying to override default ResourceBundleLocator in hibernate validation 4.1. So far it works perfectly, but the only examples of its usage include java code to instantiate ValidationFactory.
When using a web application with spring hibernate validation is automatically configured (only the suitable hibernate validation *.jar file should exist and it is automatically used). How can i substitute ResourceBundleLocator in that scenario? I do not see any way of specyfing my custom ResourceBundleLocator in any properties or applicationContext.xml file.
The magic method that does the required job is LocalValidatorFactoryBean#setValidationMessageSource(MessageSource messageSource).
First of all, contract of the method:-
You can specify your custom message.properties(or .xml) by invoking this method… like this…
my-beans.xml
validation_errors.properties
Person.java
BeanValidationTest.java
Outupt:
Custom Message:- MyNotNullMessage