Skip to content

Commit bb7ce21

Browse files
committed
Expose Locale to method validation in WebFlux
Closes gh-33810
1 parent fd4dee7 commit bb7ce21

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import reactor.core.publisher.SynchronousSink;
4040
import reactor.core.scheduler.Scheduler;
4141

42+
import org.springframework.context.i18n.LocaleContextHolder;
4243
import org.springframework.core.CoroutinesUtils;
4344
import org.springframework.core.DefaultParameterNameDiscoverer;
4445
import org.springframework.core.KotlinDetector;
@@ -186,8 +187,14 @@ public Mono<HandlerResult> invoke(
186187

187188
return getMethodArgumentValuesOnScheduler(exchange, bindingContext, providedArgs).flatMap(args -> {
188189
if (shouldValidateArguments() && this.methodValidator != null) {
189-
this.methodValidator.applyArgumentValidation(
190-
getBean(), getBridgedMethod(), getMethodParameters(), args, this.validationGroups);
190+
try {
191+
LocaleContextHolder.setLocaleContext(exchange.getLocaleContext());
192+
this.methodValidator.applyArgumentValidation(
193+
getBean(), getBridgedMethod(), getMethodParameters(), args, this.validationGroups);
194+
}
195+
finally {
196+
LocaleContextHolder.resetLocaleContext();
197+
}
191198
}
192199
Object value;
193200
Method method = getBridgedMethod();

0 commit comments

Comments
 (0)