从数据库读取messageSource
一直以来用Spring做国际化,都将国际化信息写在properties文件中。这次在项目中遇到一个需求,需要把properties文件去掉,直接从数据库读取国际化信息。
从数据库读取messageSource可以将properties文件的管理界面化,数据化。
- SPRING 国际化
- 从数据库读取messageSource
- 方便维护
- 注意:读取xml配置文件的顺序
Spring配置代码块
<!-- 定义国际化文件和编码 -->
<bean id="propertiesMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames" value="messages/message"/>
<property name="defaultEncoding" value="utf8" />
</bean>
<!-- 使用session判断用户语言 -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="cn"/>
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="locale"/>
</bean>
</mvc:interceptors>
<!-- 数据库国际化资源 自定义的MessageResource -->
<bean id=