- import java.net.URL;
- import java.util.List;
-
- import org.apache.commons.configuration.Configuration;
- import org.apache.commons.configuration.ConfigurationFactory;
-
- public class PropertiesXmlConfigurationExample {
-
- public static void main(String[] args) throws Exception {
- PropertiesXmlConfigurationExample example = new PropertiesXmlConfigurationExample();
-
- ConfigurationFactory factory = new ConfigurationFactory();
- URL configURL = example.getClass().getResource("additional-xml-configuration.xml");
- factory.setConfigurationURL( configURL );
-
- Configuration config = factory.getConfiguration();
-
- List startCriteria = config.getList("start-criteria.criteria");
- System.out.println( "Start Criteria: " + startCriteria );
-
- int horsepower = config.getInt("horsepower");
- System.out.println( "Horsepower: " + horsepower );
- }
- }
- additional-xml-configuration.xml
- <?xml version="1.0" encoding="ISO-8859-1" ?>
- <configuration>
- <properties fileName="global.properties"/>
- <xml fileName="global.xml"/>
- </configuration>
4.CompositeConfiguration,手动加上两个配置文件