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: [email protected]
For additional commands, e-mail: [email protected]



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


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

Reply via email to