wuyuyan opened SPR-15944 and commented

when we set "localeResolver" to realize the i18n dynamic switching, if we access to the jsp page directly, it's invalid.

spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/support/RequestContext.java

public RequestContext(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable ServletContext servletContext, @Nullable Map model) {

    this.request = request;
    this.response = response;
    this.model = model;

    // Fetch WebApplicationContext, either from DispatcherServlet or the root context.
    // ServletContext needs to be specified to be able to fall back to the root context!
    WebApplicationContext wac = (WebApplicationContext) request.getAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (wac == null) {
        wac = RequestContextUtils.findWebApplicationContext(request, servletContext);
        if (wac == null) {
            throw new IllegalStateException("No WebApplicationContext found: not in a DispatcherServlet " +
                    "request and no ContextLoaderListener registered?");
        }
    }
    this.webApplicationContext = wac;

    Locale locale = null;
    TimeZone timeZone = null;

    // Determine locale to use for this RequestContext.
    LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
    if (localeResolver instanceof LocaleContextResolver) {
        LocaleContext localeContext = ((LocaleContextResolver) localeResolver).resolveLocaleContext(request);
        locale = localeContext.getLocale();
        if (localeContext instanceof TimeZoneAwareLocaleContext) {
            timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
        }
    }

line 228 LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request); it's not get theLocaleResolver.


Affects: 4.3.10

Reference URL: https://github.com/spring-projects/spring-framework/compare/master...wuyuyan:patch-1

Comment From: rstoyanchev

Superseded by #1522.