Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate validation messages broken in spring boot 2.6.1 when setUseCodeAsDefaultMessage set to true #28930

Closed
runningonfumes opened this issue Dec 8, 2021 · 2 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@runningonfumes
Copy link

runningonfumes commented Dec 8, 2021

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
.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 8, 2021
@snicoll
Copy link
Member

snicoll commented Dec 8, 2021

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.

@wilkinsona
Copy link
Member

wilkinsona commented Dec 8, 2021

Thanks for the sample, @runningonfumes. The change in behaviour is an unanticipated side-effect of #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.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Dec 8, 2021
@philwebb philwebb added type: regression A regression from a previous release and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Dec 15, 2021
@philwebb philwebb added this to the 2.6.x milestone Dec 15, 2021
@scottfrederick scottfrederick self-assigned this Dec 15, 2021
@scottfrederick scottfrederick modified the milestones: 2.6.x, 2.6.2 Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

6 participants