SpringMVC国际化设置出现Cannot change HTTP accept header - use a different locale resolution strategy的BUG

时间:2018-01-28 19:12:43   收藏:0   阅读:1653

在系统的学习SpringMVC过程并进行练习时,出现Cannot change HTTP accept header - use a different locale resolution strategy的BUG。

国际化需要可以满足三个需求

1.在页面上对时间、数值、标签等进行本地化处理

2.需要从bean中获取国际化的资源文件Locale对应的消息

3.可以通过超链接动态的切换Locale

 

实现方式:

首先先配置资源文件

i18n_zh_CN.properties中文配置文件

i18n.user=\u7528\u6237\u540D
i18n.password=\u5BC6\u7801(此处是将中文转化为ascii码)

i18n_en_US.properties英文配置文件

i18n.user=User
i18n.password=Password

需求1实现

技术分享图片

需求2实现

技术分享图片

需求3解决需要配置SessionLocalResolver和LocalChangeInterceptor

SessionLocaleResolver是将Locale对象存于Session中供以后获取

技术分享图片

我的问题出在SessionLocaleResolver这里,配置这个bean的时候,id必须为localeResolver,否则就会出现我这个BUG

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!