Skip to content

Regression: Resource bundle message source custom validation message no longer resolved #23839

Closed

Description

@rgolder1

Issue:

Resource bundle message source custom validation message no longer resolved following upgrade from Spring 5.1.6.RELEASE to Spring 5.2.0.RELEASE.

DefaultListableBeanFactory preinstantiateSingletons() bean instantiation order:

  1. LocalValidatorFactoryBean "defaultValidator"
  2. RequestMappingHandlerAdapter "requestMappingHandlerAdapter"
  3. LocalValidatorFactoryBean "mvcValidator"

Spring 5.1.6 behaviour:

WebMvcConfigurationSupport requestMappingHandlerAdapter() @Bean method takes no args. It calls WebMvcAutoConfiguration mvcValidator() which calls WebMvcConfigurerComposite getValidator() which calls the getValidator() @Override in my Configuration class, which creates a LocalValidatorFactoryBean setting the ValidationMessageSource to my ReloadableResourceBundleMessageSource messageSource.

Upshot: requestMappingHandlerAdapter configured with the userResourceBundleLocator set to MessageSourceResoureBundleLocator as expected.

Spring 5.2.0 behaviour:

WebMvcConfigurationSupport requestMappingHandlerAdapter() @Bean method now takes a Validator. It is instantiated with the "defaultValidator" LocalValidatorFactoryBean. That has a PlatformResourceBundleLocator as the userResourceBundleLocator.

Upshot: requestMappingHandlerAdapter configured with the userResourceBundleLocator set to PlatformResoureBundleLocator.

Subsequently, the mvcValidator() @Bean is instantiated, but too late for use in the requestMappingHandlerAdapter.

Activity

  1. added
    status: waiting-for-triage
    on Oct 21, 2019
  2. sbrannen commented on Oct 22, 2019

    @sbrannen
    Member

    Hi @rgolder1,

    Thanks for raising the issue.

    Can you provide a minimal example that reproduces the exact issue you're encountering?

  3. added
    status: waiting-for-feedback
    on Oct 22, 2019
  4. rgolder1 commented on Oct 23, 2019

    @rgolder1
    Author
  5. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    on Oct 23, 2019
  6. sbrannen commented on Oct 23, 2019

    @sbrannen
    Member

    Thanks for the repo project!

    We'll look into it.

  7. changed the title [-]Spring 5.2.0.RELEASE: Resource bundle message source custom validation message no longer resolved[/-] [+]Regression: Resource bundle message source custom validation message no longer resolved[/+] on Oct 23, 2019
  8. added
    in: web
    type: regression
    on Oct 23, 2019
  9. added this to the 5.2.1 milestone on Oct 23, 2019
  10. sbrannen commented on Oct 23, 2019

    @sbrannen
    Member

    Thanks to the provided repro project, I can confirm that this is a regression introduced in 5.2 (at least in conjunction with Spring Boot).

    Failed tests:   testNumberTooHigh(example.ConstraintErrorIntegrationTest): expected:<[The number must not be more than 10]> but was:<[{test.api.simpleupdate.number.max}]>
    
  11. removed
    status: waiting-for-triage
    on Oct 23, 2019
  12. added
    for: external-project
    and removed
    type: regression
    on Oct 28, 2019
  13. sbrannen commented on Oct 28, 2019

    @sbrannen
    Member

    In light of spring-projects/spring-boot#18672 (comment), I am closing this issue.

  14. removed this from the 5.2.1 milestone on Oct 28, 2019
  15. added
    status: superseded
    on Oct 31, 2019
  16. sbrannen commented on Oct 31, 2019

    @sbrannen
    Member

    Please note that this issue is a duplicate of spring-projects/spring-boot#18672 (comment) (in Spring Boot) and was superseded by #23887 (in Spring Framework).

    Thus, the "fix" for this issue is the combination of the fixes in spring-projects/spring-boot#18672 (comment) and #23887.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectin: webstatus: feedback-providedstatus: superseded

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions