问题
I would like to dynamically construct a property value expression, as in
<property name="server" value="#{'${host}' + {systemProperties['myEnv']}}" />
Let's say the property host exists in a property file aand it's value is 'myserver.net' and the system property myEnv has been set to 'UAT', then this expression results in a value of 'myserver.netUAT'.
What I would like if for the whole lot to be evaluated after the concatenation. Right now it's looking up {host} key then appending the property. I would like it to lookup the key ${host.UAT}
Is it at all possible to achieve this.
回答1:
This works...
<util:properties id="props" location="foo.properties" />
<context:property-placeholder properties-ref="props" />
<bean id="foo" class="foo.Foo">
<property name="foo" value="#{props['${host}' + systemProperties['foo']]}" />
</bean>
来源:https://stackoverflow.com/questions/28191736/spring-xml-dynamic-property-placeholder-construction