讀取配置文件有很多種方法,現就最常用的方法作以下總結:(其他會慢慢更新)
configuration/ConfigurationFactory用法(pache.commons包下)
本文:org.apache.commons.configuration.configuration
其它:com.opensymphony.xwork2.config.configuration
javax.security,auth.login.configuration
net.sf.ehcache.config.configuration
org.hibernate.cfg.configuration 等等,用方類同。
1.讀取XML文件中內容
global.xml:



























2.讀取properties文件
global.properties:




















3.當有多個配置文件時,就利用ConfigurationFactory對象來訪問多個不同的配置資源
ConfigurationFactory可以組合多個配置資源。然后我們就可以像訪問單個資源文件一樣來訪問他們中的屬性。
首先,我們需要創建一個xml文件來告訴工廠哪些文件將要被加載。
additional-xml-configuration.xml:





方法1:ConfigurationFactory的定義文件是一個普通的xml文件.根元素是configuration.他飽含的子元素制定了需要裝載
的配置資源.properties是元素之一,他用來包含屬性文件




















方法2:或者采用另外一種方法: 用到了:CompositeConfiguration,手動加上兩個配置文件

























Spring的ClassPathXmlApplicationContext類(ApplicationContext接口) 和 JDK中的Properties 類(Java.util中)
1.讀取XML文件中內容
(1)java bean (HelloBean.java)



















<1>利用ClassPathXmlApplicationContext







2.讀取properties文件
(1)HelloBean.java同上
(2).properties配置文件(beanConfig.properties)


<1>利用spring讀取properties 文件
屬性文件中的"helloBean"名稱即是Bean的別名設定,.class用于指定類來源。
然后利用org.springframework.beans.factory.support.PropertiesBeanDefinitionReader來讀取屬性文件















