Browse Source

Expose Locale to method validation in WebFlux

Closes gh-33810
pull/34387/head
rstoyanchev 11 months ago
parent
commit
bb7ce21076
  1. 13
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

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

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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();

Loading…
Cancel
Save