You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by de...@apache.org on 2016/05/15 17:52:38 UTC
svn commit: r1743927 - in
/commons/proper/configuration/trunk/src/site/xdoc/userguide:
howto_utilities.xml user_guide.xml
Author: deki
Date: Sun May 15 17:52:38 2016
New Revision: 1743927
URL: http://svn.apache.org/viewvc?rev=1743927&view=rev
Log:
[CONFIGURATION-624] documentation
Modified:
commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_utilities.xml
commons/proper/configuration/trunk/src/site/xdoc/userguide/user_guide.xml
Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_utilities.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_utilities.xml?rev=1743927&r1=1743926&r2=1743927&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_utilities.xml (original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/howto_utilities.xml Sun May 15 17:52:38 2016
@@ -356,6 +356,63 @@ Configuration config = wrapperFactory.cr
Configuration.class, builder);
]]></source>
</subsection>
+
+ <subsection name="Use Configuration in Spring">
+ <p>
+ Commons Configuration integrates with the Spring framework.
+ A <code>FactoryBean</code> wraps a <code>CompositeConfiguration</code> object for usage
+ with Spring's <code>PropertiesLoaderSupport</code>.
+
+ This allows a configuration object to behave
+ <ul>
+ <li>like a normal <code>java.util.Properties</code> object which can be passed on to</li>
+ <li><code>setProperties()</code> method allowing <code>PropertyOverrideConfigurer</code> and</li>
+ <li><code>PropertyPlaceholderConfigurer</code> to take advantage of Commons Configuration.</li>
+ </ul>
+
+ Previously this functionality was provided by the spring-modules-jakarta-commons library (<code>CommonsConfigurationFactoryBean</code>).
+ As this library is no longer maintained, this is now supported directly by Commons Configuration.
+ If you've used this with Commons Configuration 1.x, just replace the spring-modules-jakarta-commons classname with
+ <code>ConfigurationPropertiesFactoryBean</code>.
+
+ Here is a sample xml configuration:
+ </p>
+ <source><![CDATA[
+<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="properties">
+ <bean class="org.apache.commons.configuration2.spring.ConfigurationPropertiesFactoryBean">
+ <constructor-arg>
+ <ref local="xmlConfiguration" />
+ </constructor-arg>
+ </bean>
+ </property>
+</bean>
+]]></source>
+ <p>
+ In addition support as a <code>PropertySource</code> was added.
+ The <code>ConfigurationPropertySource</code> can be used with e.g. with <code>ApplicationContextInitializer</code>
+ or simply added in a bean definition as follows:
+ </p>
+ <source>
+@Value("${aPropertyKey}")
+private String configurationValue;
+
+@Configuration
+static class Config {
+
+ @Bean
+ public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(ConfigurableEnvironment env)
+ throws ConfigurationException {
+ PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
+ MutablePropertySources sources = new MutablePropertySources();
+ sources.addLast(new ConfigurationPropertySource("xml configuration", new Configurations().xml("aXmlConfigFile.xml")));
+ configurer.setPropertySources(sources);
+ configurer.setEnvironment(env);
+ return configurer;
+ }
+}
+ </source>
+ </subsection>
</section>
</body>
Modified: commons/proper/configuration/trunk/src/site/xdoc/userguide/user_guide.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/xdoc/userguide/user_guide.xml?rev=1743927&r1=1743926&r2=1743927&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/xdoc/userguide/user_guide.xml (original)
+++ commons/proper/configuration/trunk/src/site/xdoc/userguide/user_guide.xml Sun May 15 17:52:38 2016
@@ -175,6 +175,7 @@
<li><a href="howto_utilities.html#Interpolation_of_all_variables">Interpolation of all variables</a></li>
<li><a href="howto_utilities.html#Handling_of_runtime_exceptions">Handling of runtime exceptions</a></li>
<li><a href="howto_utilities.html#Wrapping_Configuration_Builders">Wrapping Configuration Builders</a></li>
+ <li><a href="howto_utilities.html#Use_Configuration_in_Spring">Use Configuration in Spring</a></li>
</ul>
<li><a href="howto_concurrency.html">Configurations and Concurrent Access</a></li>
<ul>
@@ -189,4 +190,4 @@
</body>
-</document>
\ No newline at end of file
+</document>