Open thekalinga opened 8 years ago
Have you found a solution?
No..
+1
I had the same issue. Fixed it by providing my own ValidatorFactory and marking it @Primary. I'm not sure if this is a very good solution, as I don't know if just overwrote some sensible defaults normally provided by spring boot.
@Bean
@Primary
public ValidatorFactory getValidatorFactory() {
return new LocalValidatorFactoryBean();
}
The issue I had was a collision between "defaultValidator" and "mvcValidator". After spending some time with it, I "solved" it by providing two bean definitions of my own, overriding those predefined beans:
@Bean("defaultValidator") @Scope("prototype") public Validator getDefaultBeanValidator(){ return Validation.buildDefaultValidatorFactory().getValidator(); }
@Bean("mvcValidator") @Scope("prototype") public Validator getMvcBeanValidator(){ return Validation.buildDefaultValidatorFactory().getValidator(); }
Of course, Spring complained that those beans are already defined, so I also enabled overriding via applicaiton.properties: spring.main.allow-bean-definition-overriding=true
And that did the trick for me. I must say, I didn't enjoy hacking into it, I would much prefer a more clean solution.
In my project, I have an additional validator factory for Method validation along with the validator auto registered by spring boot (with name
mvcValidator
) in classpathWhen I try to validate a collection, I get the following exception
Is there a way to configure hibernate and spring to use
mvcValidator
withCommonEachValidator
when more than one validators exist in classpath?