Spring国际化--从数据库读取messageSource

从数据库读取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=
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值