标签:== conf tde fine src recipe register Fix ade
用的是springboot最新的稳定版本,在使用自定义localResolver实现国际化时,出现了错误,参照网上的文章,发现并不生效
未实现页面按照请求参数的值来显示中文还是英文,出现这种问题进行了以下排错:
在WebMvcAutoConfiguration里边自动配置的localeResolver,可以清楚的看到如下代码如果自己定义了localeResolver加载自己的,否则加载系统的
public LocaleResolver localeResolver() {
if (this.mvcProperties.getLocaleResolver() == org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.mvcProperties.getLocale());
} else {
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
localeResolver.setDefaultLocale(this.mvcProperties.getLocale());
return localeResolver;
}
}
在《Spring Boot 2 Recipes: A Problem-Solution Approach》书中提到这样一句话:
You can also define a locale resolver by registering a bean of type LocaleResolver in the web application context.
You must set the bean name of the locale resolver to localeResolver so it can be autodetected.
上述英语意思为:在自定义localeResolver时方法名必须一致,检查自己的发现确实不对
改过后方法名的如下
大致一看没有问题,但细看确实是方法名拼写错误,改过来即可实现国际化
总结:以后遇到这种情况情况少,但仍需注意,注意书写!
标签:== conf tde fine src recipe register Fix ade
原文地址:https://www.cnblogs.com/ql123456/p/12173219.html