在看springMVC源码的时候,不知道是我哪里配置错了,还是这就是springmvc的坑?

按照  DispatcherServlet 源码 说明,
注入 LocaleResolver的 实现类 SessionLocaleResolver 或 LocaleContextResolver 的bean。

即可根据浏览器语言环境的自动切花locale环境,

SessionLocaleResolver类的部分源码如下 

/**
 * Determine the default locale for the given request, //确定给定请求的默认区域设置
 * Called if no Locale session attribute has been found.
 * <p>The default implementation returns the specified default locale,
 * if any, else falls back to the request's accept-header locale.
 * @param request the request to resolve the locale for
 * @return the default locale (never {@code null})
 * @see #setDefaultLocale
 * @see javax.servlet.http.HttpServletRequest#getLocale()
 */
//protected 包外不允许掉用此方法,
protected Locale determineDefaultLocale(HttpServletRequest request) {
 Locale defaultLocale = getDefaultLocale();
 if (defaultLocale == null) {
  defaultLocale = request.getLocale();
 }
 return defaultLocale;
}

而SessionLocaleResolver 的父类  AbstractLocaleResolver.class 拥有这个方法  setDefaultLocale

源码是这样的:

/**
 * 如果没有找到其他语言环境,则设置此解析器将返回的默认语言环境。
 * Set a default Locale that this resolver will return if no other locale found.
 */
public void setDefaultLocale(@Nullable Locale defaultLocale) {
 this.defaultLocale = defaultLocale;
}

我设置了这个参数之后,

@Bean
public LocaleResolver localeResolver() {
  SessionLocaleResolver localeResolver = new SessionLocaleResolver();
  //设置默认区域
  localeResolver.setDefaultLocale(Locale.CHINA);
  return localeResolver;
}

发现;
无论我怎么修改浏览器的语言环境,都给我 返回的是 这个defaultLocale

说好的default呢,是我哪里配错了吗?求帮助

03-12 22:05