What's the best way to handle/inject complex configuration data? Lets say I have a List (Array, Hashmap...) of structured configuration data. I see the following options:
1. Externalize the config data to XML and inject only the (class/filesystem) path to the config file:
It requires reading XML in non-framework code by hand. Even if dom4j / jdom / castor could make this easy, it doesn't sound like a good idea to me.Code:<property name="xmlConfPath"><value>classpath:some/path/to/file.xml</value></propert>
2. Make a bean-class for the structured data and inject to a list of this bean type
For my taste, this is much too verbose and unreadable. In addition, I like the idea more to separate some config-data from the application-context file.Code:<property name="confList"> <list> <bean class="my.ConfClass"> <property name="id"><value>someId</value></property> <property name="foo"><value>1234</value></property> <property name="bar"><value>just an example</value></property> </bean> <bean class="my.ConfClass"> <property name="id"><value>otherId</value></property> <property name="foo"><value>4223</value></property> <property name="bar"><value>another example</value></property> </bean> </list> </property>
3. Implement some XML-ish PropertyPlaceholderConfigurer which is able to read XML data instead of properties can inject it into a configured bean.
Disadvantage: XmlPropertyPlaceholderConfigurer does not exist.Code:<bean name="xmlConfigurer" class="to.be.done.XmlPropertyPlaceholderConfigurer"> <property name="location/of/config.xml"><value>classpath:some/path/config.xml</value></property> <property name="placeholderPrefix"><value>$xml{</value></property> </bean> <bean id="configuredBean" class="some.Class"> <property name="configData"><value>$xml{complexConfigData}</value></property> </bean>
Is there a "spring-ish" way to handle such config data? The spring-config add on seems to address this issue, but adding this and commons-config sounds like a lot of unnecessary complexity to me?
Any ideas?
Thanks,
Felix


Reply With Quote