首先,程序读取取文件,
(代码中获取路径方式就比较广泛了,例:System.getProperty("user.dir");获取工作目录;不像spring配置文件中只能获取WEB-INF或者使用classpath)
String userDir=System.getProperty("user.dir");
Properties props=new Properties();
props.load(new FileInputStream(userDir+"/config.properties"));
此时,properties文件中所有的参数均被读取至系统中。
可以使用:
props.getProperty("file.monthprex");
获取参数。
接下来,讲重点,spring配置文件中读取Properties中的参数
<bean id="propertyConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
spring配置文件中加入此Bean,方可在配置文件中使用$获取所有参数