• CompositeConfiguration的用法


    public class Mytest {
    
        private static ApplicationContext applicationContext;
    
        public static void main(String[] args) throws Exception {
            
            //获取spring上下文
            applicationContext = new ClassPathXmlApplicationContext("applicationContext-config.xml");
            
            CompositeConfiguration configuration = new CompositeConfiguration();
            XMLConfiguration config = (XMLConfiguration) applicationContext.getBean("xmlConfiguration");
            configuration.addConfiguration(config);
            
            String value = configuration.getString("test.url");
            System.out.println(value);//运行结果http://www.baidu.com
        }
    }
    

      

    applicationContext-config.xml

    <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.xsd">
    
        <bean id="xmlConfiguration" class="org.apache.commons.configuration.XMLConfiguration">
              <constructor-arg index="0" type="java.net.URL" value="classpath:local-app.xml"/>
       </bean>
    </beans>
    

      

    local-app.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <appconfig>
        <test>
            <url>http://www.baidu.com</url>
        </test>
    </appconfig>
    

      

  • 相关阅读:
    Python 简单总结
    Python 简单总结
    Python 简介
    Python基础题
    Python基础题
    tDQSS
    parameter–precharge, tRCD and tRAS
    parameter–key parameters
    parameter -- tWR
    命令集
  • 原文地址:https://www.cnblogs.com/jifeng/p/5787529.html
Copyright © 2020-2023  润新知