[configuration] Interpolation over several files, commons config 1.4

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[configuration] Interpolation over several files, commons config 1.4

David J. M. Karlsen
Hi!

I'm can use interpolation within a property file with success.
But I'd like to be able to spread this over several files.

F.ex:

prop1.properties:
var1=somevalue1
var2=somevalue2


prop2.properties
myvar1=${var1}
myvar2=${var2}

so that the resulting java.util.Properties would contain these values:
var1=somevalue1
var2=somevalue2
myvar1=somevalue1
myvar2=somevalue2


I can't get this to work - even with a CompoundConfiguration.

Any pointers?

TIA,
David

--
David J. M. Karlsen - +47 90 68 22 43
http://www.davidkarlsen.com
http://mp3.davidkarlsen.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Interpolation over several files, commons config 1.4

Oliver Heger-3
David J. M. Karlsen wrote:

> Hi!
>
> I'm can use interpolation within a property file with success.
> But I'd like to be able to spread this over several files.
>
> F.ex:
>
> prop1.properties:
> var1=somevalue1
> var2=somevalue2
>
>
> prop2.properties
> myvar1=${var1}
> myvar2=${var2}
>
> so that the resulting java.util.Properties would contain these values:
> var1=somevalue1
> var2=somevalue2
> myvar1=somevalue1
> myvar2=somevalue2
>
>
> I can't get this to work - even with a CompoundConfiguration.
>
> Any pointers?
>
> TIA,
> David
>
It would be helpful if you could provide some code fragments
demonstrating what you are doing and how you are creating a
java.util.Properties object. So I am not sure what is going wrong.

Interpolation in CombinedConfiguration should work over multiple
configuration sources. But because I don't know your actual use case I
can't say whether this helps you.

Did you have a look at the include directives for
PropertiesConfiguration [1]? Maybe this is an option?

Oliver

[1]
http://commons.apache.org/configuration/userguide/howto_properties.html#Includes

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Interpolation over several files, commons config 1.4

David J. M. Karlsen
Oliver Heger skrev:

>David J. M. Karlsen wrote:
>  
>
>>Hi!
>>
>>I'm can use interpolation within a property file with success.
>>But I'd like to be able to spread this over several files.
>>
>>F.ex:
>>
>>prop1.properties:
>>var1=somevalue1
>>var2=somevalue2
>>
>>
>>prop2.properties
>>myvar1=${var1}
>>myvar2=${var2}
>>
>>so that the resulting java.util.Properties would contain these values:
>>var1=somevalue1
>>var2=somevalue2
>>myvar1=somevalue1
>>myvar2=somevalue2
>>
>>
>>I can't get this to work - even with a CompoundConfiguration.
>>
>>Any pointers?
>>
>>TIA,
>>David
>>
>>    
>>
>It would be helpful if you could provide some code fragments
>demonstrating what you are doing and how you are creating a
>java.util.Properties object. So I am not sure what is going wrong.
>  
>
See the attached spring-context which uses spring-modules to create a
org.apache.commons.configuration.CompositeConfiguration consisting of
two properties files, prop1 and prop2.

>Interpolation in CombinedConfiguration should work over multiple
>configuration sources. But because I don't know your actual use case I
>can't say whether this helps you.
>
>Did you have a look at the include directives for
>PropertiesConfiguration [1]? Maybe this is an option?
>  
>
That could be a way to go - but I'd prefer doing this with the
spring-factory bean combining the files as shown

TIA,
David

<?xml version="1.0" encoding="ISO-8859-1"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

        <bean id="configFactory" class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
                <property name="configurations">
                        <list>
                                <bean class="org.apache.commons.configuration.CompositeConfiguration">
                                        <constructor-arg>
                                                <list>
                                                        <bean class="org.apache.commons.configuration.PropertiesConfiguration">
                                                                <constructor-arg type="java.lang.String" value="prop1.properties" />
                                                        </bean>
                                                        <bean class="org.apache.commons.configuration.PropertiesConfiguration">
                                                                <constructor-arg type="java.lang.String" value="prop2.properties" />
                                                        </bean>
                                                </list>
                                        </constructor-arg>
                                </bean>
                        </list>
                </property>
        </bean>
       
        <bean id="properties" factory-bean="&amp;configFactory" factory-method="getConfiguration"/>

</beans>
prop2=value2
myalias=${placeholder1}
${myvar}=123
place=${prop2}
prop1=value1
placeholder1=placevalue1
place2=${prop2}

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [configuration] Interpolation over several files, commons config 1.4

Oliver Heger-3
David J. M. Karlsen wrote:
<snip/>

> See the attached spring-context which uses spring-modules to create a
> org.apache.commons.configuration.CompositeConfiguration consisting of
> two properties files, prop1 and prop2.
>
>> Interpolation in CombinedConfiguration should work over multiple
>> configuration sources. But because I don't know your actual use case I
>> can't say whether this helps you.
>>
>> Did you have a look at the include directives for
>> PropertiesConfiguration [1]? Maybe this is an option?
>>  
>>
> That could be a way to go - but I'd prefer doing this with the
> spring-factory bean combining the files as shown
>
> TIA,
> David

Did you test what happens if you create a CompositeConfiguration
manually and then add the sub configurations to it?

This would a) eleminate springmodules as a potential source of errors
and b) could serve as a basis for a unit test

Oliver

>
>
> ------------------------------------------------------------------------
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
>
> <bean id="configFactory" class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
> <property name="configurations">
> <list>
> <bean class="org.apache.commons.configuration.CompositeConfiguration">
> <constructor-arg>
> <list>
> <bean class="org.apache.commons.configuration.PropertiesConfiguration">
> <constructor-arg type="java.lang.String" value="prop1.properties" />
> </bean>
> <bean class="org.apache.commons.configuration.PropertiesConfiguration">
> <constructor-arg type="java.lang.String" value="prop2.properties" />
> </bean>
> </list>
> </constructor-arg>
> </bean>
> </list>
> </property>
> </bean>
>
> <bean id="properties" factory-bean="&amp;configFactory" factory-method="getConfiguration"/>
>
> </beans>
>
>
> ------------------------------------------------------------------------
>
> prop2=value2
> myalias=${placeholder1}
> ${myvar}=123
> place=${prop2}
>
>
> ------------------------------------------------------------------------
>
> prop1=value1
> placeholder1=placevalue1
> place2=${prop2}
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]