我正在使用弹簧 3.1.2 MVC。我正在尝试通过注释配置 Web 应用程序
在这里,我想实现国际化,因为我正在使用LocaleChangeInterceptor、ReloadableResourceBundleMessageSource、SessionLocaleResolver类。这是我的配置类:
@Configuration
@EnableWebMvc
public class MyAppConfig extends WebMvcConfigurerAdapter{
@Bean
public ReloadableResourceBundleMessageSource resourceBundleMessageSource(){
ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
String[] resources= {"classpath:labels","classpath:message"};
messageSource.setBasenames(resources);
return messageSource;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor(){
LocaleChangeInterceptor localeChangeInterceptor=new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("locale");
return localeChangeInterceptor;
}
@Bean
public SessionLocaleResolver sessionLocaleResolver(){
SessionLocaleResolver localeResolver=new SessionLocaleResolver();
localeResolver.setDefaultLocale(new Locale("da","DK"));
return localeResolver;
}
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
}
但这不起作用它显示默认文本
<spring:message code="login.user.password" text="Password" />
作为“密码”。
请帮我。当我在其中进行以下配置时,applicationContext.xml
它工作正常。
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:message</value>
<value>classpath:labels</value>
</list>
</property>
<property name="defaultEncoding" value="ISO-8859-1" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="locale"/>
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="da_DK" />
</bean>
请帮我解决这个问题。