Announcement Announcement Module
No announcement yet.
Using Spring and Commons Configuration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Spring and Commons Configuration


    I want to use the commons configuration with my spring configuration so that the commons configuration mechanism is used for reading the properties from where evere there coming from and then they can be passed to the beans via the ${parameter.value} mechanism that can beused with a properties file.

    Does anybody have and example for the classes that i will need the commons config into to do this?

    The site is :

  • #2
    Answering my own question

    After looking around i figured it out so i thought i would share

    So we need three elements to create the configuration you need a
    1. PropertiesPlaceholderConfigurer [Spring-Core]
    2. CommonsConfigurationFactoryBean [Sprint Modules]
    3. Configurer [Commons Configuration]

    The configurer is used for loading the properties, It can be any implementation in this case its a DatabaseConfiguration.

    That CommonsConfigurationFactoryBean is initialised with the configurer

    The PropertyPlaceholderConfigurer is then initialied at this time it takes a properties object from the CommonsConfigurationFactoryBean and when the getObject method is called on the factory bean it uses the Configuration to load the properties

    An example configuration is below.

    <bean name="PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      	<property name="properties" ref="CommonsConfigurationFactoryBean"/>
    <bean name="CommonsConfigurationFactoryBean" class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
           <constructor-arg ref="DatabaseConfiguration"/>
    <bean name="DatabaseConfiguration" class="org.apache.commons.configuration.DatabaseConfiguration">
            <constructor-arg type="javax.sql.DataSource" ref="someDataSource"/>
            <constructor-arg index="1" value="APPLICATION_PROPERTIES_TABLE"/>
            <constructor-arg index="2" value="KEY"/>
            <constructor-arg index="3" value="VALUE"/>
    Now other beans can use the values that matched the key by placing ${keyName} in the file
    Last edited by danielp; Jul 25th, 2008, 01:00 AM. Reason: Including where classes came from