Configuration: Value not overriding

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Configuration: Value not overriding

jax-4
Hi.

I need to clarify the following about commons
configuration.

Commons configuration can make use of a substitution
technique as follows.

file: application1.properties
key1 = ${key2}
key2 = key2value
key3 = key3value

This will result in key1=key2value

Now, say i got another file

file: application2.properties
key2 = keyXvalue

This file is loaded into a compositeconfiguration as
follows,

CompositeConfiguration config = new
CompositeConfiguration();
config.addConfiguration(new
PropertiesConfiguration("application1.properties"));
config.addConfiguration(new
PropertiesConfiguration("application2.properties"));

Will key2 now be key2value or keyXvalue or an array of
both?
Consequently, will key1 be key2value or keyXvalue
after application2.properties is loaded?

Please advice.



 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Configuration: Value not overriding

Oliver Heger
Tan Kah Siong schrieb:

> Hi.
>
> I need to clarify the following about commons
> configuration.
>
> Commons configuration can make use of a substitution
> technique as follows.
>
> file: application1.properties
> key1 = ${key2}
> key2 = key2value
> key3 = key3value
>
> This will result in key1=key2value
>
> Now, say i got another file
>
> file: application2.properties
> key2 = keyXvalue
>
> This file is loaded into a compositeconfiguration as
> follows,
>
> CompositeConfiguration config = new
> CompositeConfiguration();
> config.addConfiguration(new
> PropertiesConfiguration("application1.properties"));
> config.addConfiguration(new
> PropertiesConfiguration("application2.properties"));
>
> Will key2 now be key2value or keyXvalue or an array of
> both?
> Consequently, will key1 be key2value or keyXvalue
> after application2.properties is loaded?
>
> Please advice.
>
>
CompositeConfiguration evaluates keys by processing the contained
configurations in the order they were added. When the first match is
found, processing stops.

In your case that means, that application1.properties will be searched
first. Here the value "key2value" will be found and returned.

More information about this topic, including how to create a union
configuration using ConfigurationFactory, can be found in the Howtos on
the main site of commons-configuration. Have a look at [1] and [2].

HTH
Oliver

[1]
http://jakarta.apache.org/commons/configuration/howto_configurationfactory.html
[2] http://jakarta.apache.org/commons/configuration/howto_xml.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]