-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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:
- LocalValidatorFactoryBean "defaultValidator"
- RequestMappingHandlerAdapter "requestMappingHandlerAdapter"
- 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.