commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rusty Wright <rusty.wri...@gmail.com>
Subject Re: [CONFIGURATION] need help with DefaultConfigurationBuilder and CombinedConfiguration
Date Sat, 20 Dec 2008 00:13:57 GMT
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


Mime
View raw message