Hi,
I’ve stumbled over some strange behavior regarding internationalization of validation error messages in a spring-boot application using webflux. But I think the error is related to spring-framework and webflux.
When I’m validating fields in the request body, the language of occurring validation error messages can be changed via the Accept-Language
HTTP header. This is done automatically because the AcceptHeaderLocaleContextResolver
is used during the validation process.
Although when I’m validating a URL query parameter or a path variable (e.g. via the @Size
validation annotation), the AcceptHeaderLocaleContextResolver
is not used during the validation and the validation error message is always generated in the language of the JVM locale.
Is this the correct behavior?
I’v attached a small demo project.
In the DemoApplicationTests
class there are the testBodyValidationErrorForLocaleEN
and testBodyValidationErrorForLocaleDE
methods which are passing without errors. The testPathVariableValidationErrorForLocaleEN
and testPathVariableValidationErrorForLocaleDE
methods are not passing (or at least one of them regarding your JVM locale)
Tested Version: Spring-boot: 3.3.5 (Which is using Spring-framework: 6.1.14)
Comment From: quaff
I confirm the inconsistent behavior, webmvc is not affected.
Comment From: rstoyanchev
Internationalized messages in Jakarta Validation depend on a MessageInterpolator
, and the one set up in LocalValidatorFactoryBean
depends on a ThreadLocal set up by LocaleContextHolder
. On Spring MVC this works throughout request handling, but on WebFlux we need to establish the ThreadLocal context where needed. We did that for arguments in #21764, but it's not done yet for method validation.