adeelmahmood
adeelmahmood

Reputation: 2431

spring property resolution from a spring expression

I want to resolve a property and specify the name of the property using a Spel expression. If I do this

<property name="host" value="#{T(...Constants).SINK_PROP_HOST}" />

the value gets resolved correctly to sink.host which is the value of this constant. Taking it a step further

<property name="host" value="${#{T(...Constants).SINK_PROP_HOST}}" />

This doesn't works. Any ideas how I can make it work. Essentially it should function the same as

<property name="host" value="${sink.host}" />

Upvotes: 1

Views: 161

Answers (1)

Gary Russell
Gary Russell

Reputation: 174729

You can't do that, because properties are resolved before SpEL (you can do it the other way around).

This works...

public class Foo {

    public static final String FOO = "foo.prop";

}


<util:properties id="props">
    <prop key="foo.prop">bar</prop>
</util:properties>

<bean id="xx" class="foo.Bar">
    <property name="foo" value="#{props[T(foo.Foo).FOO]}"/>
</bean>

You can, of course, load your "props" bean from a file.

Upvotes: 0

Related Questions