Configuring the following messageSource breaks hibernate validation messages

@Bean
public MessageSource messageSource() {
    var resourceBundleMessageSource = new ResourceBundleMessageSource();
    resourceBundleMessageSource.setUseCodeAsDefaultMessage(true);
    return resourceBundleMessageSource;
}

attached is a simple test case where the defaultMessage is the key, not the expected translation.

If that test is run against spring boot 2.5.7 it is fine, against 2.6.1 it is broken demo.zip .

Comment From: snicoll

Thanks for the report. Spring Boot 2.6 switched to Hibernate Validator 7 and downgrading it to the version used by Spring Boot 2.5.x didn't fix the problem so we'll have to investigate.

Comment From: wilkinsona

Thanks for the sample, @runningonfumes. The change in behaviour is an unanticipated side-effect of https://github.com/spring-projects/spring-boot/pull/17530. You can restore the previous behaviour by defining your own validator:

@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public static LocalValidatorFactoryBean customValidator() {
    LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
    MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory();
    factoryBean.setMessageInterpolator(interpolatorFactory.getObject());
    return factoryBean;
}

To make this easier, we could perhaps introduce a configuration property that allows you to opt out of using the MessageSource for validation message interpolation. Flagging for team attention so that we can consider our options.