Hi Rainer, On 01.04.2016 23:52, Rainer Hirschmiller wrote: > Hi. > > I'm trying configurations2 and PropertiesConfiguration. I have created a > helper class doing some error handling and configuration for > ProperiesConfiguration. Especially I load properties from different > property files. I want to do this to define basic configurations in one > file and be able to override these configurations in a second file which > will be loaded later. > > Getting the property of such a double defined key which public <T> T > get(final Class<T> cls, final String key) I got the first defined value. > OK, I've overriden the method to get the last defined value. > > But I want to know why the behaviour is at it is. Is there a special > reason? I think returning the last defined value would be preferred by > other users allthough. What's do other users think about this behaviour?
when multiple configuration files are loaded into a PropertiesConfiguration a union of the configuration settings is created. In your case, you get a property with multiple values, and querying this property with a get method that returns only a single value selects the first value per default. With getList() you could query all values of this property. IIUC, what you want to achieve is an override semantics. The preferred way to do this with Commons Configuration is using a CombinedConfigurationBuilder. This builder reads a definition file that references multiple configuration sources and constructs a combined configuration out of it. You can control how this combination is done, e.g. with union or override semantics. Please have a look at the user's guide: http://commons.apache.org/proper/commons-configuration/userguide/howto_combinedbuilder.html There is a section "Overriding properties" that should describe your use case. Oliver > > Regards > Rainer > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
