将上下文:属性占位符位置与Spring EL一起使用

将上下文:属性占位符位置与Spring EL一起使用,spring,spring-el,Spring,Spring El,我正在尝试使用属性占位符加载一些属性文件,我想使用系统属性指定其中一个文件的名称,以便根据我的应用程序运行的环境加载不同的文件 最初,我尝试了以下方法: <context:property-placeholder location="classpath:environment_common.properties,classpath:environment_${app_env}.properties" /> 它看起来像是context:property placeholder有自己的

我正在尝试使用属性占位符加载一些属性文件,我想使用系统属性指定其中一个文件的名称,以便根据我的应用程序运行的环境加载不同的文件

最初,我尝试了以下方法:

<context:property-placeholder location="classpath:environment_common.properties,classpath:environment_${app_env}.properties" />
它看起来像是
context:property placeholder
有自己的解析器寻找逗号来分隔多个属性文件,但它并不是首先将值传递给SpEL来对其求值


我应该如何使用
context:property placeholder
,还是绕过它直接使用
PropertyPlaceHolderConfigurer

我从未尝试在属性占位符元素中直接使用SpEL。不过,似乎有人提出申请。作为一个相当简单的解决方法:

<context:property-placeholder properties-ref="props" />
<util:properties id="props" location="#{ your expression here }"/>

我今天遇到了这个问题。以下是我的解决方案:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" 
        value="classpath:#{(T(java.lang.System).getProperty('my.property', 'development.properties'))}"/>
</bean> 

我没有使用预定义的变量systemProperties,但假设您可以,如果您愿意的话。

Bugreported:
<context:property-placeholder properties-ref="props" />
<util:properties id="props" location="#{ your expression here }"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" 
        value="classpath:#{(T(java.lang.System).getProperty('my.property', 'development.properties'))}"/>
</bean>