commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Ritchie <>
Subject Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.
Date Wed, 16 Sep 2009 11:37:04 GMT
2009/9/15 Oliver Heger <>:
> Martin Ritchie schrieb:
>> 2009/9/14 Oliver Heger <>:
>>> Martin Ritchie schrieb:
>>>> Hi,
>>>> I have been reading the Configuration Builder docs
>>>> (
>>>> and have been trying to get the configuration below to take my
>>>> optional configuration.
>>>> However, both the test.config property and the resulting file must
>>>> exist even though I have marked the config as optional. Can someone
>>>> with more understanding of commons configuartion take a look at the
>>>> config below and point out what I've done wrong?
>>>> Regards
>>>> Martin
>>>> <configuration>
>>>>  <system/>
>>>>  <override>
>>>>      <xml fileName="${test.config}" config-optional="true"/>
>>>>      <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
>>>>      <xml fileName="${TEST_HOME}/etc/config.xml"/>
>>>>  </override>
>>>> </configuration>
>>> Maybe you can provide a short code fragment demonstrating how you load
>>> this
>>> configuration. What exactly happens, do you get an exception?
>>> Per default, the configuration builder logs an exception if it cannot
>>> create
>>> a configuration marked as optional. But this should not have any further
>>> consequences.
>>> Oliver
>> Hi Oliver,
>> I've put the code and errors up here:
>> Perhaps I'm misunderstanding quite how the Configuration works. I
>> would have expected that an optional value would be skipped if it
>> cannot resolve the variables in the name or the file does not exist.
>> If the default behaviour is to create the optional configuration then
>> I can understand my first exception as I have not defined variable ;
>> test.config. However I can't understand the second exception occurs
>> because the file does not exist and so the default behaviour of
>> creating the file should proceed.
>> Thanks again for your help
>> Martin
> Whether the variable for the file name exists or not is not checked, the
> configuration always tries to load the file.
> The second exception is probably caused by your usage of
> ConfigurationFactory. Try DefaultConfigurationBuilder instead. Its API is
> very similar to the one of ConfigurationFactory, but it is more powerful and
> thus it is recommended to use this class. IIRC ConfigurationFactory does not
> understand the "config-optional" attribute - it only knows the "optional"
> attribute.
> Oliver
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Thanks for the pointer to use DefaultConfigurationBuilder.

Whilst this now does not need to have the test.config property defined
or the file existing it does behave differently to the older

With the configuration as shown in the pastie
( the ConfigurationFactory builds a single
configuration tree where later elements are overwritten by newer
So given the configuration values shown here:
The value of in config.xml (MemoryMessageStore) is
overwritten with (SlowMessageStore) from the test.config. The
additional values in the test.config are also propgated in to the
final configuraiton.

When I changed to use the DefaultConfigurationBuilder the entire
virtualhosts section was overwritten as a result the other virtualhost
sections in config.xml were lost.

Is there a way I can get the behaviour as seen with the
ConfigurationFactory but have the file parsing/loading of the


Martin Ritchie

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message