JSR validator bean missing if a custom Spring Validator bean is present
See original GitHub issueThis problem occurred after upgrade from Spring Boot 1.5.2 to 1.5.3.
I have some custom Spring validator beans for Spring Data REST while also relying on standard JSR validator in other parts of the application.
After upgrading from Spring Boot 1.5.2 to 1.5.3 there is no longer a JSR validator bean present.
Error:
Bean method 'defaultValidator' in 'DefaultValidatorConfiguration' not loaded because @ConditionalOnMissingBean (types: javax.validation.Validator,org.springframework.validation.Validator; SearchStrategy: all) found beans 'beforeSaveUserValidator', 'beforeCreateGroupValidator', 'beforeCreateUserValidator'
Debug auto configuration:
DefaultValidatorConfiguration#defaultValidator:
Did not match:
- @ConditionalOnMissingBean (types: javax.validation.Validator,org.springframework.validation.Validator; SearchStrategy: all) found beans 'beforeSaveUserValidator', 'beforeCreateGroupValidator', 'beforeCreateUserValidator' (OnBeanCondition)
https://github.com/spring-projects/spring-boot/commit/c9561f031c591ca55e028ca66250511c5e62002a changed this behaviour since it does not provide a validator if a Spring validator is present.
Not sure if this is should be considered a bug and I can easily work around this problem and provide this bean myself, but perhaps Spring Boot could create a JSR validator if not present?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
JSR-303 validation is ignored when custom ... - Stack Overflow
I've noticed that JSR-303 validation is completely ignored in Spring when a custom Validator bean annotated with @Component is declared.
Read more >Spring Validation Example - Spring MVC Form Validator
For using custom validator, first we need to inject it in the controller class. We are using spring bean auto wiring to achieve...
Read more >Validation in Spring Boot - Baeldung
Learn how to validate domain objects in Spring Boot using Hibernate Validator, the reference implementation of the Bean Validation ...
Read more >Validation with Hibernate Validator - Quarkus
This guide covers how to use Hibernate Validator/Bean Validation for: validating the input/output of your REST services;. validating the parameters and ...
Read more >Request Validation in Spring Boot - SpringExamples
Bean Validation 2.0 (JSR 380) is the specification of the Java API for JavaBean validation that provides a class-level constraint ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Superb! Thank you!
@snicoll Finally i had time to take a look at this issue and managed to workaround it. We were returning
javax.validation.ValidationFactoryas bean type so the following condition created new beandefaultValidator.The fix was to return the LocalValidatorFactoryBean type instead of ValidatorFactory.
@Bean public LocalValidatorFactoryBean beanValidatorFactory()