Spring中属性占位符配置器PropertyPlaceholderConfigurer



classpath:/spring/include/dbQuery.properties

其中classpath是引用src目录下的文件写法。当存在多个Properties文件时,配置就需使用locations了。

使用多个PropertyPlaceholderConfigurer来分散配置,达到整合多工程下的多个分散的Properties 文件,其配置如下:

 

figurer">



classpath:/spring/include/dbQuery.properties






classpath:/spring/include/jdbc-parms.properties
classpath:/spring/include/base-config.properties


其中order属性代表其加载顺序,而ignoreUnresolvablePlaceholders为是否忽略不可解析的Placeholder,如配置了多个PropertyPlaceholderConfigurer,则需设置为true。

PropertyPlaceholderConfigurer可以将${...}替换为指定的properties文件或system properties中的值。这样一来,我们就可以不再配置文件中为bean注入数值,而改用properties文件,可以降低耦合性,以后如果需要修改诸如数值,只修改properties文件就可以了。

 

你可能感兴趣的:(技术点滴)