PropertyPlaceholderConfigurer使用

PropertyPlaceholderConfigurer这个类,这个类能够把${}内所有配置的变量,根据location配置的Properties合并起来

进行替换掉,配置如下:

<bean id="propertyConfigurer"

                   class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

                   <property name="locations">

                            <list>

                                     <value>classpath:/systemConfig.properties</value>

                                     <value>classpath:/urlConfig.properties</value>

                            </list>

                   </property>

         </bean>

类的架构思想非常不错,只要配置下文件,简单使用。我就想到了国际化文件,以及普通的配置文件,也可以采用其思想,特别对于一些非spring标准化的文件,特别能够起到实质性的作用,因为非spring标准化的XML文件,并不能严格意义转换为xmlbeanfactory,当然也无需麻烦转换过去,只需要采用PropertyPlaceholderConfigurer基本设计理念,然后进行封装,重写postProcessBeanFactoryprocessProperties方法,达到效果就是把非spring标准化的xml文件,存有根据变量值,根据properites文件,进行不同场景的替换。

猜你喜欢

转载自cywhoyi.iteye.com/blog/1539381