Spring 中加载资源文件
来源:互联网 发布:游戏编程入门 李军 pdf 编辑:程序博客网 时间:2024/05/01 04:48
在Spring 中可以使用以下两个类加载资源文件:
org.springframework.context.support.ResourceBundleMessageSource
和
org.springframework.context.support.ReloadableResourceBundleMessageSource
后者可以不重起服务器的情况下,读取资源文件,所以可以随时更改资源文件。
以下为在其配置:
- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
- <property name="basename">
- <value>ApplicationResources</value>
- </property>
- </bean>
- <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
- <property name="basename">
- <value>ApplicationResources</value>
- </property>
- </bean>
当上下文件配置文件被读取后,以在配置文件中指定的名字为基名的资源文件全部会被读入,并置于上下文中,这样以后就可以在上下文中读取,在页面上也可以使用Spring标签取得。
public class MessageSourceHelper {
private ResourceBundleMessageSource messageSource;
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
String msg = messageSource.getMessage(code, args, defaultMessage, locale);
return msg != null ? msg.trim() : msg;
}
public void setMessageSource(ResourceBundleMessageSource messageSource) {
this.messageSource = messageSource;
}
}
- Spring 中加载资源文件
- Spring 中加载资源文件
- Spring 中加载资源文件
- spring加载资源文件
- spring加载资源文件
- SPRING 加载资源文件
- spring 加载资源文件
- spring加载资源文件中classpath*与classpath的区别
- Spring中@ImportResource和@Value加载资源文件
- Spring中加载外部资源文件的几种方式
- XCode中加载资源文件
- 程序中加载资源文件
- Spring加载资源文件的配置
- Spring中资源的加载ResourceLoader
- Spring中加载属性文件
- spring中加载properties文件
- Spring中加载属性文件
- CImage从资源中加载图片文件
- javascript内部函数this指向问题
- Daily-C-Study(9):C语言void关键字
- 电阻式触摸屏和电容式触摸屏区别
- hdu1232
- SSL/TLS协议簇加解密流程
- Spring 中加载资源文件
- SVN功能小结 .
- 黑马程序员-高新技术(代理)
- Gameloft
- 【模式识别】感知器 Perceptron
- WPF使用资源绑定自定义类型
- php:自动创建多级文件夹
- UML面向对象中的图及各种图的作用
- git