You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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)
The text was updated successfully, but these errors were encountered:
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.
rstoyanchev
changed the title
WebFlux: AcceptHeaderLocaleContextResolver is not used during method parameter validation
Ensure Locale context is available for WebFlux method validation
Feb 4, 2025
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 theAcceptHeaderLocaleContextResolver
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), theAcceptHeaderLocaleContextResolver
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.
demo.zip
In the
DemoApplicationTests
class there are thetestBodyValidationErrorForLocaleEN
andtestBodyValidationErrorForLocaleDE
methods which are passing without errors. ThetestPathVariableValidationErrorForLocaleEN
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)
The text was updated successfully, but these errors were encountered: