From 33931b3216e8b8681465aa8504ae238ebe882ddd Mon Sep 17 00:00:00 2001 From: halo Date: Wed, 10 Jun 2026 09:50:53 +0900 Subject: [PATCH] GH-36738: Document rendering-scope limitation of WebFlux RequestContext.changeLocale() The Spring MVC RequestContext.changeLocale() delegates through the configured LocaleResolver and persists the locale across requests. The WebFlux equivalent only updates a field on the current RequestContext instance and the change is discarded at the end of the rendering cycle. This asymmetry was undocumented, leading developers to expect that calling changeLocale() in a WebFlux template would produce the same durable effect as in Spring MVC. Add Javadoc to both WebFlux overloads explaining that the change affects only the current rendering context, does not delegate to a LocaleContextResolver, and pointing developers towards the correct approach (WebFilter + LocaleContextResolver) for durable locale changes. Co-Authored-By: Claude Sonnet 4.6 --- .../reactive/result/view/RequestContext.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java index 624fd0ce493a..8a7656da483f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RequestContext.java @@ -134,6 +134,16 @@ public TimeZone getTimeZone() { /** * Change the current locale to the specified one. + *

Note: Unlike the Spring MVC counterpart, this method only + * updates the locale within the scope of the current {@code RequestContext} instance + * for view rendering purposes. It does not delegate to a + * {@link org.springframework.web.server.i18n.LocaleContextResolver} and the change + * is not persisted beyond the current rendering cycle. For a durable locale change + * across requests in WebFlux, configure a + * {@link org.springframework.web.server.i18n.LocaleContextResolver} and update it + * from a {@link org.springframework.web.server.WebFilter} or handler method instead. + * @param locale the new locale + * @see #changeLocale(java.util.Locale, java.util.TimeZone) */ public void changeLocale(Locale locale) { this.locale = locale; @@ -141,6 +151,14 @@ public void changeLocale(Locale locale) { /** * Change the current locale to the specified locale and time zone context. + *

Note: Unlike the Spring MVC counterpart, this method only + * updates the locale and time zone within the scope of the current + * {@code RequestContext} instance for view rendering purposes. It does not + * delegate to a {@link org.springframework.web.server.i18n.LocaleContextResolver} + * and the change is not persisted beyond the current rendering cycle. + * @param locale the new locale + * @param timeZone the new time zone + * @see #changeLocale(java.util.Locale) */ public void changeLocale(Locale locale, TimeZone timeZone) { this.locale = locale;