File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -4676,6 +4676,18 @@ By default use of `@EnableWebMvc` or `<mvc:annotation-driven>` automatically reg
4676
4676
Validation support in Spring MVC through the `LocalValidatorFactoryBean` when a Bean Validation
4677
4677
provider is such as Hibernate Validator is detected on the classpath.
4678
4678
4679
+ [NOTE]
4680
+ ====
4681
+ Sometimes it's convenient to have a `LocalValidatorFactoryBean` injected into a controller
4682
+ or another class. The easiest way to do that is to declare your own `@Bean` and also mark it
4683
+ with `@Primary` in order to avoid a conflict with the one provided with the MVC Java config.
4684
+
4685
+ If you prefer to use the one from the MVC Java config, you'll need to override the
4686
+ `mvcValidator` method from `WebMvcConfigurationSupport` and declare the method to explicitly
4687
+ return `LocalValidatorFactory` rather than `Validator`. See <<mvc-config-advanced-java>>
4688
+ for information on how to switch to extend the provided configuration.
4689
+ ====
4690
+
4679
4691
Alternatively you can configure your own global `Validator` instance:
4680
4692
4681
4693
[source,java,indent=0]
You can’t perform that action at this time.
0 commit comments