spring的xml配置文件,能够方便地读取properties文件中的值。
读取单个属性文件:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:password.properties"/>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:a1.properties</value>
<value>classpath:a2.properties</value>
</list>
</property>
</bean>
不过spring自带的PropertyPlaceholderConfigurer是将属性文件中的值原样读出。实际上一般的密码等敏感信息,项目中都会进行加密存储。也就是说properties中存储的是加密后的结果,这样必需解密后才能使用。