Expose Locale to method validation in WebFlux

Closes gh-33810
This commit is contained in:
rstoyanchev
2025-02-04 16:56:44 +00:00
parent fd4dee7ce3
commit bb7ce21076

View File

@@ -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();