Skip to content

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

@rgolder1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectNeeds a fix in external projectin: webIssues in web modules (web, webmvc, webflux, websocket)status: feedback-providedFeedback has been providedstatus: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions