Spring自动注入properties文件
1. 因为在下面要用到Spring的<util />配置,所以,首先要引入其对应的命名空间,即要在applicationContext.xml中加入以下的配置:
test=testdata
4. 让Spring载入资源文件,在applicationContext.xml 加入以下配置:
/**
* @Description: 系统相关的常量类
* @Author: Jianguo Shang
* @Createtime: 2014-07-11 23:20
*/
@Component
public class SysConf {
@Value("${sys.test}")
private String test;
@Value("${sys.test}")
public void setTest(String test){
test = test;
}
@Value("${sys}")
public void setSysConf(Properties sys){
test= sys.getProperty("test");
}
} 注意:这里的${sys} 是与第四步的id=sys 相对应的