You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bean validation not picking error translations anymore #18672
I have a spring boot application with default bean validation through hibernate validator.
I'm using custom messageSource - which in fact just picks up translations from diferrent places.
On my model classes I'm using custom messages like:
Using this setup with Spring Boot 2.1.9 everything works fine and my messages are picked up correctly.
With 2.2.0 it shows "{validation.error.name.blank}" as a result. When there is no custom message on annotation: @NotBlank then it shows default message found in ValidationMessages.properties inside validation jar like "must not be blank".
In my WebMvcConfiguration I'm defining validator bean:
This looks like a duplicate of spring-projects/spring-framework#23839. Let's flag this one on hold and let the framework team figures things out before we start investigating here.
changed the title [-]Spring Boot 2.2.0 bean validation not picking error translations[/-][+]Bean validation not picking error translations anymore[/+]on Oct 23, 2019
The framework regression has been confirmed so please watch the related issue. If something needs to be done here once the issue has been fixed, we can reopen this issue.
It's a timing issue and the fact that the mvcValidator method in EnableWebMvcConfiguration can no longer do its job anymore. To accommodate with various scenarios, we have an override of this method that makes sure to expose either a user-configured mvc validator or the auto-configured one if none is present.
When we moved to non-proxied configuration class, the bean methods no longer forces the mvcValidator method to be invoked prior to create the RequestMappingHandlerAdapter. As the ValidationAutoConfiguration runs first, there is a bean that matches the requested predicate and can be used.
Having said all that, I find it odd that the context does not realize there is going to be two beans of that type in the context ultimately. If we ask for a Validator and there is one bean in the context, and one extra bean definition that hasn't been instantiated yet, I'd expect the context to fail with a resolution failure.
With the help of @jhoeller, I've something that works locally by adding @Qualifier("mvcValidator") on the injection point. Without that and since we have a @Primary validator, the context doesn't bother to create any other instance.
We should revisit the existing tests as we have at least one that is supposed to cover that exact use case.
Activity
snicoll commentedon Oct 21, 2019
This looks like a duplicate of spring-projects/spring-framework#23839. Let's flag this one on hold and let the framework team figures things out before we start investigating here.
[-]Spring Boot 2.2.0 bean validation not picking error translations[/-][+]Bean validation not picking error translations anymore[/+]snicoll commentedon Oct 23, 2019
The framework regression has been confirmed so please watch the related issue. If something needs to be done here once the issue has been fixed, we can reopen this issue.
wiecia commentedon Oct 23, 2019
Thank you
sbrannen commentedon Oct 28, 2019
I have reproduced the regression in the following standalone test class.
If you run the test class as-is, it passes.
If you redeclare
WebConfigas follows...... the test then fails.
In light of that, I suggest that this issue be reopened and investigated on the Boot side.
If there are then steps that need to be taken in Framework, please let us know!
sbrannen commentedon Oct 28, 2019
See spring-projects/spring-framework@47c8d1d#diff-410b847334e563dc406577806c2d2027 for the changes in Spring MVC that may be the root cause of this regression.
snicoll commentedon Oct 29, 2019
It's a timing issue and the fact that the
mvcValidatormethod inEnableWebMvcConfigurationcan no longer do its job anymore. To accommodate with various scenarios, we have an override of this method that makes sure to expose either a user-configured mvc validator or the auto-configured one if none is present.When we moved to non-proxied configuration class, the bean methods no longer forces the
mvcValidatormethod to be invoked prior to create theRequestMappingHandlerAdapter. As theValidationAutoConfigurationruns first, there is a bean that matches the requested predicate and can be used.Having said all that, I find it odd that the context does not realize there is going to be two beans of that type in the context ultimately. If we ask for a
Validatorand there is one bean in the context, and one extra bean definition that hasn't been instantiated yet, I'd expect the context to fail with a resolution failure.snicoll commentedon Oct 29, 2019
With the help of @jhoeller, I've something that works locally by adding
@Qualifier("mvcValidator")on the injection point. Without that and since we have a@Primaryvalidator, the context doesn't bother to create any other instance.We should revisit the existing tests as we have at least one that is supposed to cover that exact use case.