spring中进行国际化
来源:互联网 发布:supfire神火官方淘宝 编辑:程序博客网 时间:2024/06/05 02:49
最近做的项目是使用ejb3,所以好长时间没接触spring,连最基本的东西都忘了,下面就记录一下,spring中消息处理机制(i18n或国际化):
spring中常用进行消息处理的类有ResourceBundleMessageSource和ReloadableResourceBundleMessageSource,其配置如下:
1.ReloadableResourceBundleMessageSource配置:
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="utf-8"></property>
<property name="basenames">
<array>
<value>classpath:messages</value>
<value>classpath:validationMessage</value>
</array>
</property>
<!-- 表示2分钟后重新扫描配置文件 -->
<property name="cacheSeconds" value="120"></property>
</bean>
2.ResourceBundleMessageSource配置:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<array>
<value>classpath:messages</value>
<value>classpath:validationMessage</value>
</array>
</property>
</bean>
主要区别:
1.ReloadableResourceBundleMessageSource可以设置国际化文件编码,而ResourceBundleMessageSource不行。
2.ReloadableResourceBundleMessageSource能够动态加载国际化配置文件,当改变国际化文件后,不需要重启服务。
3.加载国际化文件的方式不一样
spring中加载配置文件的方式:
当一个ApplicationContext被加载时,它会自动在context中查找已定义为MessageSource类型的bean。此bean的名称须为messageSource。如果找到,那么所有对上述方法的调用将被委托给该bean。否则ApplicationContext会在其父类中查找是否含有同名的bean。如果有,就把它作为MessageSource。如果它最终没有找到任何的消息源,一个空的StaticMessageSource将会被实例化,使它能够接受上述方法的调用。
- spring中进行国际化
- Spring在代码中国际化
- Angular2中使用ngx-translate进行国际化
- Veloctiy中使用Spring国际化标签
- spring中国际化的简单配置
- 浅谈spring框架中集成国际化+velocity
- spring中MessageSource实现国际化i18n
- Spring在代码中获取国际化信息
- Spring国际化
- spring国际化
- spring 国际化
- spring 国际化
- spring国际化
- spring 国际化
- spring国际化
- spring 国际化
- spring 国际化
- Spring 国际化
- c++类内强制类型转换&访问共享文件夹提示0未知的用户名或密码错误
- 21天学通C++--阅读笔记2
- Linux 文件时间详解 ctime mtime atime
- hdu 5171 矩阵快速幂
- Java学习之序列化
- spring中进行国际化
- RPM包创建入门
- IIS发布网站
- Android 分析android 客户端保持session 不过期的方式
- Mega Fiers 变形插件
- 离深...
- Hadoop分布式文件系统:架构和设计要点
- 解决ntpdate error: no server suitable for synchronization found
- java多线程面试问题