Hi,

Mingfai Ma wrote:
how do you design your system to load static configuration? ...
I do it like this.
There is a configuration subsystem. It has one main configuration file "application.properties" which is located in classpath. Then there is java class (Configuration) which has static access so application can access it from everywhere and doesn't need to perform any instantiation because Configuration class can load "application.properties" from the classpath.

So, when I have "application.properties" like this:
prop1=value1
prop2=value2
then I access these properties by invoking:
[Prefix]Properties props = Configuration.getProperties();
props.getProperty("prop1");

There is pluggable system to extend properties. If I need properties to be loaded from other source then I add special configuration properties to "application.properties":

configuration.loader.props1=org.xxx.FilePropertyLoader
configuration.loader.props1.file=my.properties
configuration.loader.props2=org.xxx.FilePropertyLoader
configuration.loader.props2.file=another.properties
configuration.loader.props2.prefix=my_prefix.
configuration.loader.props3=org.xxx.XmlPropertyLoader
configuration.loader.props3.file=some_more.xml
configuration.loader.props3.prefix=this_comes_from_xml.

Now properties from three files "my.properties", "another.properties" and "some_more.xml" are loaded and available from Configuration.getProperties(). Properties from "my.properties" file are available directly and properties from "another.properties" are available under prefix "my_prefix.".

PrefixProperties class has a method getPrefixedProperties(String prefix):PrefixProperties so you can easily retrieve properties under prefix:
Configuration.getProperties().getPrefixedProperties("my_prefix.");

One thing which I miss in jakarta-commons-configuration is that it has no static access to it.

Regards
Vilmantas

--
Vilmantas Baranauskas
Phone: +49-711/13353-47 FAX: +49-711/1335353
D A N E T - IS GmbH, Waldburgstrasse 17 - 19, D-70563 Stuttgart
Email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to