May be its late. But it could come help with others.
Actually you need LocalValidatorFactoryBean
in your context to explicitly call the validator. In your any context you could decalre the bean like
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource"/>
</bean>
In your controller Autowire
the bean and call explicitly for validate()
method
@Autowired
private Validator validator;
@Autowired
private MyCustomValidator customValidator;
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.addValidators(smartValidator, customValidator);
}
public String save(@ModelAttribute FooModel foo, BindingResult result) {
// ... your cutom logic and processing
validator.validate(foo, bindingResult);
customValidator.validate(foo, bindingResult);
if (result.hasErrors()) {
// ... on any validation errors
}
return "view";
}
You could go through this for more about this scenario