我的applicationContext中可以有多个PropertyPlaceHolderConfigurer吗? [英] Is it possible to have multiple PropertyPlaceHolderConfigurer in my applicationContext?

查看:76
本文介绍了我的applicationContext中可以有多个PropertyPlaceHolderConfigurer吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据给定的系统属性加载特定的applicationContext.xml文件。这本身加载具有实际配置的文件。因此,我需要2个PropertyPlaceHolderConfigurer,一个解析系统参数,另一个解析实际配置。

I need to load a specific applicationContext.xml file according to a given system property. This itself loads a file with the actual configuration. Therefore I need 2 PropertyPlaceHolderConfigurer, one which resolves the system param, and the other one within the actual configuration.

任何想法如何做到这一点?

Any ideas how to do this?

推荐答案

是的,你可以做多个。一定要设置 ignoreUnresolvablePlaceholders ,以便第一个将忽略它无法解析的任何占位符。

Yes you can do more than one. Be sure to set ignoreUnresolvablePlaceholders so that the first will ignore any placeholders that it can't resolve.

<bean id="ppConfig1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="ignoreUnresolvablePlaceholders" value="true"/>
   <property name="locations">
    <list>
             <value>classpath*:/my.properties</value>
    </list>
  </property>
</bean>

<bean id="ppConfig2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="ignoreUnresolvablePlaceholders" value="false"/>
   <property name="locations">
    <list>
             <value>classpath*:/myOther.properties</value>
    </list>
  </property>
</bean>

根据您的应用程序,您应该调查systemPropertiesMode,它允许您从文件加载属性,但是允许系统属性覆盖属性文件中的值(如果已设置)。

Depending on your application, you should investigate systemPropertiesMode, it allows you to load properties from a file, but allow the system properties to override values in the property file if set.

这篇关于我的applicationContext中可以有多个PropertyPlaceHolderConfigurer吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆