From bb7ce210764004d7da8b3d05eb371495d6792db0 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Tue, 4 Feb 2025 16:56:44 +0000 Subject: [PATCH] Expose Locale to method validation in WebFlux Closes gh-33810 --- .../result/method/InvocableHandlerMethod.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index 836a7753088..32ae18c6d08 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import reactor.core.publisher.Mono; import reactor.core.publisher.SynchronousSink; import reactor.core.scheduler.Scheduler; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.CoroutinesUtils; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.KotlinDetector; @@ -186,8 +187,14 @@ public class InvocableHandlerMethod extends HandlerMethod { return getMethodArgumentValuesOnScheduler(exchange, bindingContext, providedArgs).flatMap(args -> { if (shouldValidateArguments() && this.methodValidator != null) { - this.methodValidator.applyArgumentValidation( - getBean(), getBridgedMethod(), getMethodParameters(), args, this.validationGroups); + try { + LocaleContextHolder.setLocaleContext(exchange.getLocaleContext()); + this.methodValidator.applyArgumentValidation( + getBean(), getBridgedMethod(), getMethodParameters(), args, this.validationGroups); + } + finally { + LocaleContextHolder.resetLocaleContext(); + } } Object value; Method method = getBridgedMethod();