Spring i18n问号而不是文本

时间:2016-03-26 18:02:55

标签: java spring localization internationalization

我hava i18n,但遇到俄语字母的问题。我有问号?????而不是文字。配置:

@Bean
public LocaleResolver localeResolver(){
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(new Locale("ru"));
    resolver.setCookieName("locale");
    resolver.setCookieMaxAge(60 * 60 * 24 * 365 * 10);
    return resolver;
}

@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
    LocaleChangeInterceptor changeInterceptor = new LocaleChangeInterceptor();
    changeInterceptor.setParamName("lang");
    return changeInterceptor;
}

@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:/i18n/messages");
    messageSource.setDefaultEncoding("UTF-8");
    return messageSource;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(localeChangeInterceptor());
}

我也在使用Thymeleaf。

<h1 th:text="#{message}"></h1>

1 个答案:

答案 0 :(得分:0)

只是猜测:在“addInterceptor”中,您自己手动构建LocaleChangeInterceptor。如果此类依赖于其他spring bean(如MessageSource),则不会注入这些类。找到一种让spring实例化LocaleChangeInterceptor的方法(例如,通过使用应用程序上下文的各种getBean())。