Java Spring-如何使用PropertyPlaceHolderConfigure动态加载文件
我有Spring框架的下一个属性文件 配置属性Java Spring-如何使用PropertyPlaceHolderConfigure动态加载文件,java,spring,properties,Java,Spring,Properties,我有Spring框架的下一个属性文件 配置属性 心满意足 environment=devel //posible values: devel, testing, prod 使用“上一个环境”属性,选择以下一些文件以动态加载 config-service1-devel.properties config-service1-testing.properties config-service1-prod.properties config-serviceN-devel.properties conf
心满意足
environment=devel //posible values: devel, testing, prod
使用“上一个环境”属性,选择以下一些文件以动态加载
config-service1-devel.properties
config-service1-testing.properties
config-service1-prod.properties
config-serviceN-devel.properties
config-serviceN-testing.properties
config-serviceN-prod.properties
然后,使用spring,我想加载属性,我想加载第一个属性文件,但我不知道如何使用表达式语言来完成依赖属性的值
<bean id="MainApplicationProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"
value="file://#{systemProperties['jboss.server.home.dir']}/conf/services.properties" />
<property name="placeholderPrefix" value="$mainProperty{" />
<property name="placeholderSuffix" value="}" />
</bean>
<bean id="SecondApplicationProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
depends-on="MainApplicationProperties">
<property name="locations">
<list>
<value>file://#{systemProperties['jboss.server.home.dir']}/conf/serviceOne/service1-$mainProperty{environment}.properties</value>
<value>file://#{systemProperties['jboss.server.home.dir']}/conf/serviceTwo/service2-$mainProperty{environment}.properties</value>
<value>file://#{systemProperties['jboss.server.home.dir']}/conf/serviceN/serviceN-$mainProperty{environment}.properties</value>
</list>
</property>
</bean>
我的观点是,价值并没有被取代
帮帮我,谢谢问题是当开始调用
BeanFactoryPostProcessors
时,它们已经被实例化了。因此,即使第一个propertyplaceholderconfigure
修改了第二个propertyplaceholderconfigure
的bean定义,也没有任何效果,因为两个bean都已实例化。PropertyPlaceHolder'的'locations'属性,没有通过表达式语言的评估过程来检索位置的真实价值,问题是,为什么EL不处理“位置”属性的价值?我复制了行为并更新了我的答案。。。你想做的是不可能的。
java.io.FileNotFoundException: /..../conf/serviceOne/service1-$mainProperty{environment}.properties (No such file or directory)