commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: Commons Config Interpolation not working
Date Fri, 07 Mar 2008 19:37:43 GMT
jonathan doklovic schrieb:
> Hi,
> 
> I'm using commons-config-1.5
> I have created a Configuration class that extends CombinedConfiguration
> and I can't get property interpolation to work.
> 
> I decided to step back and just try a simple test case, and I can get
> that to work either. Here's what I have:
> 
> testPropExpansion.properties
> -----------------------------
> base.prop=root
> client.prop=got ${base.prop}?
> 
> 
> TestPropertyExpansion.java
> -----------------------------
> @Test
> public void genericExpansion() throws Exception {
>     File props = new File("testPropExpansion.properties");
>     Configuration cfg = new PropertiesConfiguration(props);
>     assert cfg.getProperty("client.prop").equals("got root?") :
> "expected: got root? received: " + cfg.getProperty("client.prop");
> 
> }
> 
> 
> Test output
> --------------
> genericExpansion - Failure - expected: got root? received: got
> ${base.prop}?
> 
> java.lang.AssertionError: expected: got root? received: got
> ${base.prop}?
> at
> com.ibsys.headline.config.TestPropertyExpansion.genericExpansion(TestPropertyExpansion.java:17)
> ... Removed 22 stack frames
> 
> Why is this test failing?
> 
> - Jonathan
> 
The getProperty() method you use for obtaining the property value does 
not do any interpolation. (This is also stated in the Javadocs.) Use the 
getString() method instead.

This is a frequently asked question. Maybe we should change something to 
make this more obvious?

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message