This document describes the steps required to get spring-config up and running in your application using Jakarta Commons Configuration as the configuration agent. You're going to need to satisfy it's dependencies in order to get your application up and running. It's also probably worth reading the Customizing bean factories with BeanFactoryPostprocessors section of the Spring reference document to get a better idea of how spring-config does it's magic.
Firstly you'll need to register the configuration agent with spring's bean factory. You can use the factory provided with Commons Configuration or the wrapper that is provided as part of the spring-config package.
In this example we'll be using spring-config's factory wrapper. I'm also going to presume that you have added the configuration.xml file into the root of your classpath. In your applicationContext.xml add the bean definition for the configuration factory.
<bean id="commonsConfigurationFactory" class="org.reactive.configuration.CommonsConfigurationFactory" singleton="true"> <property name="configurationResource"> <value>classpath:/configuration.xml</value> </property> </bean>
Now you will need to add the bean definition for the configuration instance that is returned from the above factory.
<bean id="configuration" factory-bean="commonsConfigurationFactory" factory-method="getConfiguration" />
The ConfigurationPlaceholderProcessor class performs the bulk of the work in spring-config. It coordinates between your configuration agent (defined above) and spring's bean factory to substitute placeholders with objects returned from the configuration agent.
The placeholder processor requires that a placeholder evaluator be registered in order to look up the configured values. In the below example we set the placeholderEvaluator property to the Commons Configuration implementation.
<bean id="configurationPlaceholderProcessor" class="org.reactive.beans.factory.config.ConfigurationPlaceholderProcessor"> <property name="placeholderEvaluator"> <bean class="org.reactive.beans.factory.config.commons.CommonsPlaceholderEvaluator"> <property name="configuration"> <ref bean="configuration"/> </property> </bean> </property> </bean>
Now that we have told Spring about the configuration placeholder processor we can start adding placeholders to your bean definition files. Take a look at the syntax page for details on spring-config's place holder syntax.