- PropertyPlaceholderConfigurer是spring提供的properties文件的键值加载器,可以指定多个properties文件位置以及指定文件的编码格式,配置如下
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
<property name="fileEncoding" value="utf-8" />
</bean>
- 在实际的应用中一般对其进行简单扩展,以便开发者能够更好的得到Properties文件里面的键值,一般通过重写其processProperties()方法,将解析后得到的Properties键值存入其Map私有的静态域中,提供静态公共方法,通过键名获取属性。因为在processProperties(),Properties键值已经被解析完成,如图:
