Spring xml dynamic property placeholder construction

北城以北 提交于 2019-12-25 04:07:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!