spring bean的分散配置(a.properties文件读取的第四种方式)

见韩顺平的spring 第12讲

她 把原本需要在<bean><property name="${username}" value="${password}"/><bean> 中配置的property放在一个a.properties文件中,自己通过el表达式取值。

其中,a.properties的初始化通过spring 提供的特殊bean ----PropertyPlaceHolderConfigure(分散配置bean)来处理。不需要写什么,只需要配置下下就好了:<bean class="org....PropertyPlaceHolderConfigure">

            <property name="locations">

              <list>

                <value>com/test/properties/a.properties</value>

                <value>com/test/properties/b.properties</value>

              </list>

            </property>

          </bean>

更简单的配置: <context:property-placeholder location="com/test/properties/a.properties,com/test/properties/a.properties"/> 即可

补充:四种获得a.properties 里面值的方法

1. ResourceBundle,见我博客

2.filter 继承类咯有个fiterConfig,见上篇博客

3.propertiesConfiguration

4.此篇

原文地址:https://www.cnblogs.com/yanjunwu/p/3000456.html