You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rusty Wright <ru...@gmail.com> on 2008/12/19 02:59:13 UTC
[CONFIGURATION] need help with DefaultConfigurationBuilder and CombinedConfiguration
I'm using Spring to autowire things together; in my Spring test-applicationContext.xml I have
<bean id="configurationBuilder" class="org.apache.commons.configuration.DefaultConfigurationBuilder">
<property name="fileName" value="test-config-xml.xml" />
</bean>
In test-config-xml.xml I have
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<xml
config-name="ftp"
fileName="properties/ftp.xml"
/>
<xml
config-name="email"
fileName="properties/email.xml"
/>
</configuration>
And ftp.xml contains
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ftp>
<server>${ftp.server}</server>
<login>${ftp.login}</login>
<password>${ftp.password}</password>
<siteCmd>${ftp.siteCmd}</siteCmd>
</ftp>
The ${} placeholders are replaced by maven when I run my tests. The email.xml file contains similar entries.
In my class that uses the DefaultConfigurationBuilder, it's injected by Spring in its constructor:
@Autowired
public FtpEdt(final DefaultConfigurationBuilder configBuilder)
throws ConfigurationException {
super();
final CombinedConfiguration combinedConfig = configBuilder.getConfiguration(true);
final Configuration config = combinedConfig.getConfiguration("ftp");
this.server = config.getString("server");
if (this.server == null)
throw (new IllegalStateException("server not set"));
The problem is when the Email class's constructor is called, which looks very similar, it blows up on the configBuilder.getConfiguration(true); with
Caused by: org.apache.commons.configuration.ConfigurationRuntimeException: A configuration with the name 'ftp' already exists in this combined configuration!
at org.apache.commons.configuration.CombinedConfiguration.addConfiguration(CombinedConfiguration.java:315) [commons-configuration-1.5.jar:1.5]
at org.apache.commons.configuration.DefaultConfigurationBuilder.initCombinedConfiguration(DefaultConfigurationBuilder.java:572) [commons-configuration-1.5.jar:1.5]
at org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:501) [commons-configuration-1.5.jar:1.5]
at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:41) [classes/:na]
...
So I guess I don't understand how to use the CombinedConfiguration and the DefaultConfigurationBuilder; can someone give me some hints for how to do this?
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and
CombinedConfiguration
Posted by Rusty Wright <ru...@gmail.com>.
Thanks; yes it will solve the problem if it calls getConfiguration(true) only once.
Ralph Goers wrote:
> Yes, that would be true. However, if you use the Spring factory then you
> should be able to inject both your beans with the same configuration.
>
> On Dec 18, 2008, at 8:33 PM, Rusty Wright wrote:
>
>> Thanks; I'll try the Spring factory.
>>
>> It seems rather unfortunate that the no arg version of
>> getConfiguration() returns Configuration while the boolean arg version
>> returns CombinedConfiguration. Because I'm paranoid, and it seems
>> bogus to just blithely cast the return value from the no arg method,
>> I'll use the Spring factory which allows you to specify a method
>> argument.
>>
>> I didn't explain all of my investigation as to why it's blowing up; it
>> seems to be because you can't call getConfiguration(true) more than
>> once, in my situation at least where the config is unchanging, a file
>> on disk. So my Ftp class was getting called with
>> getConfiguration(true) and then the Email class was doing that too.
>> If I changed the Email class to use false instead of true then it
>> didn't blow up.
>>
>> Ralph Goers wrote:
>>> First, why not do
>>> <bean id="configurationBuilder"
>>> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
>>> <property name="fileName" value="test-config-xml.xml"/>
>>> </bean
>>> <bean id="appConfig" factory-bean="configurationBuilder"
>>> factory-method="getConfiguration"/>
>>> Then declare your component to take a CombinedConfiguration instead
>>> of the builder.
>>> Next, you've supplied the constructor for a class named FtpEdt yet
>>> your stack trace shows the failure in a class named Email. What is
>>> that class doing?
>>> Ralph
>>> On Dec 18, 2008, at 5:59 PM, Rusty Wright wrote:
>>>> I'm using Spring to autowire things together; in my Spring
>>>> test-applicationContext.xml I have
>>>>
>>>> <bean id="configurationBuilder"
>>>> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
>>>> <property name="fileName" value="test-config-xml.xml" />
>>>> </bean>
>>>>
>>>> In test-config-xml.xml I have
>>>>
>>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>>>
>>>> <configuration>
>>>> <xml
>>>> config-name="ftp"
>>>> fileName="properties/ftp.xml"
>>>> />
>>>>
>>>> <xml
>>>> config-name="email"
>>>> fileName="properties/email.xml"
>>>> />
>>>> </configuration>
>>>>
>>>> And ftp.xml contains
>>>>
>>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>>>
>>>> <ftp>
>>>> <server>${ftp.server}</server>
>>>>
>>>> <login>${ftp.login}</login>
>>>>
>>>> <password>${ftp.password}</password>
>>>>
>>>> <siteCmd>${ftp.siteCmd}</siteCmd>
>>>> </ftp>
>>>>
>>>> The ${} placeholders are replaced by maven when I run my tests. The
>>>> email.xml file contains similar entries.
>>>>
>>>> In my class that uses the DefaultConfigurationBuilder, it's injected
>>>> by Spring in its constructor:
>>>>
>>>> @Autowired
>>>> public FtpEdt(final DefaultConfigurationBuilder configBuilder)
>>>> throws ConfigurationException {
>>>> super();
>>>>
>>>> final CombinedConfiguration combinedConfig =
>>>> configBuilder.getConfiguration(true);
>>>>
>>>> final Configuration config =
>>>> combinedConfig.getConfiguration("ftp");
>>>>
>>>> this.server = config.getString("server");
>>>>
>>>> if (this.server == null)
>>>> throw (new IllegalStateException("server not set"));
>>>>
>>>> The problem is when the Email class's constructor is called, which
>>>> looks very similar, it blows up on the
>>>> configBuilder.getConfiguration(true); with
>>>>
>>>> Caused by:
>>>> org.apache.commons.configuration.ConfigurationRuntimeException: A
>>>> configuration with the name 'ftp' already exists in this combined
>>>> configuration!
>>>> at
>>>> org.apache.commons.configuration.CombinedConfiguration.addConfiguration(CombinedConfiguration.java:315)
>>>> [commons-configuration-1.5.jar:1.5]
>>>> at
>>>> org.apache.commons.configuration.DefaultConfigurationBuilder.initCombinedConfiguration(DefaultConfigurationBuilder.java:572)
>>>> [commons-configuration-1.5.jar:1.5]
>>>> at
>>>> org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:501)
>>>> [commons-configuration-1.5.jar:1.5]
>>>> at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:41)
>>>> [classes/:na]
>>>> ...
>>>>
>>>> So I guess I don't understand how to use the CombinedConfiguration
>>>> and the DefaultConfigurationBuilder; can someone give me some hints
>>>> for how to do this?
>>>>
>>>> Thanks
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and CombinedConfiguration
Posted by Ralph Goers <ra...@dslextreme.com>.
Yes, that would be true. However, if you use the Spring factory then
you should be able to inject both your beans with the same
configuration.
On Dec 18, 2008, at 8:33 PM, Rusty Wright wrote:
> Thanks; I'll try the Spring factory.
>
> It seems rather unfortunate that the no arg version of
> getConfiguration() returns Configuration while the boolean arg
> version returns CombinedConfiguration. Because I'm paranoid, and it
> seems bogus to just blithely cast the return value from the no arg
> method, I'll use the Spring factory which allows you to specify a
> method argument.
>
> I didn't explain all of my investigation as to why it's blowing up;
> it seems to be because you can't call getConfiguration(true) more
> than once, in my situation at least where the config is unchanging,
> a file on disk. So my Ftp class was getting called with
> getConfiguration(true) and then the Email class was doing that too.
> If I changed the Email class to use false instead of true then it
> didn't blow up.
>
> Ralph Goers wrote:
>> First, why not do
>> <bean id="configurationBuilder"
>> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
>> <property name="fileName" value="test-config-xml.xml"/>
>> </bean
>> <bean id="appConfig" factory-bean="configurationBuilder" factory-
>> method="getConfiguration"/>
>> Then declare your component to take a CombinedConfiguration instead
>> of the builder.
>> Next, you've supplied the constructor for a class named FtpEdt yet
>> your stack trace shows the failure in a class named Email. What is
>> that class doing?
>> Ralph
>> On Dec 18, 2008, at 5:59 PM, Rusty Wright wrote:
>>> I'm using Spring to autowire things together; in my Spring test-
>>> applicationContext.xml I have
>>>
>>> <bean id="configurationBuilder"
>>> class
>>> ="org.apache.commons.configuration.DefaultConfigurationBuilder">
>>> <property name="fileName" value="test-config-xml.xml" />
>>> </bean>
>>>
>>> In test-config-xml.xml I have
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>>
>>> <configuration>
>>> <xml
>>> config-name="ftp"
>>> fileName="properties/ftp.xml"
>>> />
>>>
>>> <xml
>>> config-name="email"
>>> fileName="properties/email.xml"
>>> />
>>> </configuration>
>>>
>>> And ftp.xml contains
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>>
>>> <ftp>
>>> <server>${ftp.server}</server>
>>>
>>> <login>${ftp.login}</login>
>>>
>>> <password>${ftp.password}</password>
>>>
>>> <siteCmd>${ftp.siteCmd}</siteCmd>
>>> </ftp>
>>>
>>> The ${} placeholders are replaced by maven when I run my tests.
>>> The email.xml file contains similar entries.
>>>
>>> In my class that uses the DefaultConfigurationBuilder, it's
>>> injected by Spring in its constructor:
>>>
>>> @Autowired
>>> public FtpEdt(final DefaultConfigurationBuilder configBuilder)
>>> throws ConfigurationException {
>>> super();
>>>
>>> final CombinedConfiguration combinedConfig =
>>> configBuilder.getConfiguration(true);
>>>
>>> final Configuration config =
>>> combinedConfig.getConfiguration("ftp");
>>>
>>> this.server = config.getString("server");
>>>
>>> if (this.server == null)
>>> throw (new IllegalStateException("server not set"));
>>>
>>> The problem is when the Email class's constructor is called, which
>>> looks very similar, it blows up on the
>>> configBuilder.getConfiguration(true); with
>>>
>>> Caused by:
>>> org.apache.commons.configuration.ConfigurationRuntimeException: A
>>> configuration with the name 'ftp' already exists in this combined
>>> configuration!
>>> at
>>> org
>>> .apache
>>> .commons
>>> .configuration
>>> .CombinedConfiguration.addConfiguration(CombinedConfiguration.java:
>>> 315) [commons-configuration-1.5.jar:1.5]
>>> at
>>> org
>>> .apache
>>> .commons
>>> .configuration
>>> .DefaultConfigurationBuilder
>>> .initCombinedConfiguration(DefaultConfigurationBuilder.java:572)
>>> [commons-configuration-1.5.jar:1.5]
>>> at
>>> org
>>> .apache
>>> .commons
>>> .configuration
>>> .DefaultConfigurationBuilder
>>> .getConfiguration(DefaultConfigurationBuilder.java:501) [commons-
>>> configuration-1.5.jar:1.5]
>>> at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:
>>> 41) [classes/:na]
>>> ...
>>>
>>> So I guess I don't understand how to use the CombinedConfiguration
>>> and the DefaultConfigurationBuilder; can someone give me some
>>> hints for how to do this?
>>>
>>> Thanks
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and
CombinedConfiguration
Posted by Rusty Wright <ru...@gmail.com>.
Thanks; I'll try the Spring factory.
It seems rather unfortunate that the no arg version of getConfiguration() returns Configuration while the boolean arg version returns CombinedConfiguration. Because I'm paranoid, and it seems bogus to just blithely cast the return value from the no arg method, I'll use the Spring factory which allows you to specify a method argument.
I didn't explain all of my investigation as to why it's blowing up; it seems to be because you can't call getConfiguration(true) more than once, in my situation at least where the config is unchanging, a file on disk. So my Ftp class was getting called with getConfiguration(true) and then the Email class was doing that too. If I changed the Email class to use false instead of true then it didn't blow up.
Ralph Goers wrote:
> First, why not do
>
> <bean id="configurationBuilder"
> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
> <property name="fileName" value="test-config-xml.xml"/>
> </bean
> <bean id="appConfig" factory-bean="configurationBuilder"
> factory-method="getConfiguration"/>
>
> Then declare your component to take a CombinedConfiguration instead of
> the builder.
>
> Next, you've supplied the constructor for a class named FtpEdt yet your
> stack trace shows the failure in a class named Email. What is that class
> doing?
>
> Ralph
>
> On Dec 18, 2008, at 5:59 PM, Rusty Wright wrote:
>
>> I'm using Spring to autowire things together; in my Spring
>> test-applicationContext.xml I have
>>
>> <bean id="configurationBuilder"
>> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
>> <property name="fileName" value="test-config-xml.xml" />
>> </bean>
>>
>> In test-config-xml.xml I have
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>
>> <configuration>
>> <xml
>> config-name="ftp"
>> fileName="properties/ftp.xml"
>> />
>>
>> <xml
>> config-name="email"
>> fileName="properties/email.xml"
>> />
>> </configuration>
>>
>> And ftp.xml contains
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>
>> <ftp>
>> <server>${ftp.server}</server>
>>
>> <login>${ftp.login}</login>
>>
>> <password>${ftp.password}</password>
>>
>> <siteCmd>${ftp.siteCmd}</siteCmd>
>> </ftp>
>>
>> The ${} placeholders are replaced by maven when I run my tests. The
>> email.xml file contains similar entries.
>>
>> In my class that uses the DefaultConfigurationBuilder, it's injected
>> by Spring in its constructor:
>>
>> @Autowired
>> public FtpEdt(final DefaultConfigurationBuilder configBuilder)
>> throws ConfigurationException {
>> super();
>>
>> final CombinedConfiguration combinedConfig =
>> configBuilder.getConfiguration(true);
>>
>> final Configuration config =
>> combinedConfig.getConfiguration("ftp");
>>
>> this.server = config.getString("server");
>>
>> if (this.server == null)
>> throw (new IllegalStateException("server not set"));
>>
>> The problem is when the Email class's constructor is called, which
>> looks very similar, it blows up on the
>> configBuilder.getConfiguration(true); with
>>
>> Caused by:
>> org.apache.commons.configuration.ConfigurationRuntimeException: A
>> configuration with the name 'ftp' already exists in this combined
>> configuration!
>> at
>> org.apache.commons.configuration.CombinedConfiguration.addConfiguration(CombinedConfiguration.java:315)
>> [commons-configuration-1.5.jar:1.5]
>> at
>> org.apache.commons.configuration.DefaultConfigurationBuilder.initCombinedConfiguration(DefaultConfigurationBuilder.java:572)
>> [commons-configuration-1.5.jar:1.5]
>> at
>> org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:501)
>> [commons-configuration-1.5.jar:1.5]
>> at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:41)
>> [classes/:na]
>> ...
>>
>> So I guess I don't understand how to use the CombinedConfiguration and
>> the DefaultConfigurationBuilder; can someone give me some hints for
>> how to do this?
>>
>> Thanks
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and CombinedConfiguration
Posted by Ralph Goers <ra...@dslextreme.com>.
First, why not do
<bean id="configurationBuilder"
class="org.apache.commons.configuration.DefaultConfigurationBuilder">
<property name="fileName" value="test-config-xml.xml"/>
</bean
<bean id="appConfig" factory-bean="configurationBuilder" factory-
method="getConfiguration"/>
Then declare your component to take a CombinedConfiguration instead of
the builder.
Next, you've supplied the constructor for a class named FtpEdt yet
your stack trace shows the failure in a class named Email. What is
that class doing?
Ralph
On Dec 18, 2008, at 5:59 PM, Rusty Wright wrote:
> I'm using Spring to autowire things together; in my Spring test-
> applicationContext.xml I have
>
> <bean id="configurationBuilder"
> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
> <property name="fileName" value="test-config-xml.xml" />
> </bean>
>
> In test-config-xml.xml I have
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <configuration>
> <xml
> config-name="ftp"
> fileName="properties/ftp.xml"
> />
>
> <xml
> config-name="email"
> fileName="properties/email.xml"
> />
> </configuration>
>
> And ftp.xml contains
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <ftp>
> <server>${ftp.server}</server>
>
> <login>${ftp.login}</login>
>
> <password>${ftp.password}</password>
>
> <siteCmd>${ftp.siteCmd}</siteCmd>
> </ftp>
>
> The ${} placeholders are replaced by maven when I run my tests. The
> email.xml file contains similar entries.
>
> In my class that uses the DefaultConfigurationBuilder, it's injected
> by Spring in its constructor:
>
> @Autowired
> public FtpEdt(final DefaultConfigurationBuilder configBuilder)
> throws ConfigurationException {
> super();
>
> final CombinedConfiguration combinedConfig =
> configBuilder.getConfiguration(true);
>
> final Configuration config =
> combinedConfig.getConfiguration("ftp");
>
> this.server = config.getString("server");
>
> if (this.server == null)
> throw (new IllegalStateException("server not set"));
>
> The problem is when the Email class's constructor is called, which
> looks very similar, it blows up on the
> configBuilder.getConfiguration(true); with
>
> Caused by:
> org.apache.commons.configuration.ConfigurationRuntimeException: A
> configuration with the name 'ftp' already exists in this combined
> configuration!
> at
> org
> .apache
> .commons
> .configuration
> .CombinedConfiguration.addConfiguration(CombinedConfiguration.java:
> 315) [commons-configuration-1.5.jar:1.5]
> at
> org
> .apache
> .commons
> .configuration
> .DefaultConfigurationBuilder
> .initCombinedConfiguration(DefaultConfigurationBuilder.java:572)
> [commons-configuration-1.5.jar:1.5]
> at
> org
> .apache
> .commons
> .configuration
> .DefaultConfigurationBuilder
> .getConfiguration(DefaultConfigurationBuilder.java:501) [commons-
> configuration-1.5.jar:1.5]
> at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:41)
> [classes/:na]
> ...
>
> So I guess I don't understand how to use the CombinedConfiguration
> and the DefaultConfigurationBuilder; can someone give me some hints
> for how to do this?
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and
CombinedConfiguration
Posted by Rusty Wright <ru...@gmail.com>.
Ok, thanks.
Ralph Goers wrote:
>
> On Dec 19, 2008, at 4:13 PM, Rusty Wright wrote:
>
>> I haven't looked at this but possibly it could help:
>>
>> org
>> .springmodules.commons.configuration.CommonsConfigurationFactoryBean
>>
>
> I looked at this a while ago. As I recall it creates a
> CompositeConfiguration which isn't Hierarchical so you can't use it very
> well with XML files. Also, I've tried to enhance
> DefaultConfigurationBuilder so that everything it needs is within its
> configuration file since it can be difficult to configure with Spring.
> I'll be continuing to make more enhancements in that area.
>
> Ralph
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and CombinedConfiguration
Posted by Ralph Goers <ra...@dslextreme.com>.
On Dec 19, 2008, at 4:13 PM, Rusty Wright wrote:
> I haven't looked at this but possibly it could help:
>
> org
> .springmodules.commons.configuration.CommonsConfigurationFactoryBean
>
I looked at this a while ago. As I recall it creates a
CompositeConfiguration which isn't Hierarchical so you can't use it
very well with XML files. Also, I've tried to enhance
DefaultConfigurationBuilder so that everything it needs is within its
configuration file since it can be difficult to configure with Spring.
I'll be continuing to make more enhancements in that area.
Ralph
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and
CombinedConfiguration
Posted by Rusty Wright <ru...@gmail.com>.
I haven't looked at this but possibly it could help:
org.springmodules.commons.configuration.CommonsConfigurationFactoryBean
Rusty Wright wrote:
> I'm using Spring to autowire things together; in my Spring
> test-applicationContext.xml I have
>
> <bean id="configurationBuilder"
> class="org.apache.commons.configuration.DefaultConfigurationBuilder">
> <property name="fileName" value="test-config-xml.xml" />
> </bean>
>
> In test-config-xml.xml I have
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <configuration>
> <xml
> config-name="ftp"
> fileName="properties/ftp.xml"
> />
>
> <xml
> config-name="email"
> fileName="properties/email.xml"
> />
> </configuration>
>
> And ftp.xml contains
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <ftp>
> <server>${ftp.server}</server>
>
> <login>${ftp.login}</login>
>
> <password>${ftp.password}</password>
>
> <siteCmd>${ftp.siteCmd}</siteCmd>
> </ftp>
>
> The ${} placeholders are replaced by maven when I run my tests. The
> email.xml file contains similar entries.
>
> In my class that uses the DefaultConfigurationBuilder, it's injected by
> Spring in its constructor:
>
> @Autowired
> public FtpEdt(final DefaultConfigurationBuilder configBuilder)
> throws ConfigurationException {
> super();
>
> final CombinedConfiguration combinedConfig =
> configBuilder.getConfiguration(true);
>
> final Configuration config = combinedConfig.getConfiguration("ftp");
>
> this.server = config.getString("server");
>
> if (this.server == null)
> throw (new IllegalStateException("server not set"));
>
> The problem is when the Email class's constructor is called, which looks
> very similar, it blows up on the configBuilder.getConfiguration(true); with
>
> Caused by:
> org.apache.commons.configuration.ConfigurationRuntimeException: A
> configuration with the name 'ftp' already exists in this combined
> configuration!
> at
> org.apache.commons.configuration.CombinedConfiguration.addConfiguration(CombinedConfiguration.java:315)
> [commons-configuration-1.5.jar:1.5]
> at
> org.apache.commons.configuration.DefaultConfigurationBuilder.initCombinedConfiguration(DefaultConfigurationBuilder.java:572)
> [commons-configuration-1.5.jar:1.5]
> at
> org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:501)
> [commons-configuration-1.5.jar:1.5]
> at edu.berkeley.ist.cars.net.email.Email.<init>(Email.java:41)
> [classes/:na]
> ...
>
> So I guess I don't understand how to use the CombinedConfiguration and
> the DefaultConfigurationBuilder; can someone give me some hints for how
> to do this?
>
> Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org