Spring中的ClassPathXmlApplicationContext源碼詳解
ClassPathXmlApplicationContext源碼
ApplicationContext應(yīng)用上下文體系如下:

在實(shí)現(xiàn)類ClassPathXmlApplicationContext中其實(shí)并沒有多少重要的操作,主要是在構(gòu)造函數(shù)中配置Spring配置文件的路徑:
public class DaoOperationMain {
public static void main(String[] args) {
ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext.xml");
}
}具體的applicationContext.xml解析相關(guān)的操作都在父類refresh中進(jìn)行操作。
ClassPathXmlApplicationContext的源碼如下:
/**
* 并沒有太多具體的操作,主要是初始化構(gòu)造函數(shù),主要的操作都在父類中
*/
public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {
private Resource[] configResources;
public ClassPathXmlApplicationContext() {
}
public ClassPathXmlApplicationContext(ApplicationContext parent) {
super(parent);
}
public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
this(new String[] {configLocation}, true, null);
}
public ClassPathXmlApplicationContext(String... configLocations) throws BeansException {
this(configLocations, true, null);
}
public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {
this(configLocations, true, parent);
}
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {
this(configLocations, refresh, null);
}
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
throws BeansException {
super(parent);
//設(shè)置spring的配置文件
setConfigLocations(configLocations);
if (refresh) {
//調(diào)用父類的refresh函數(shù),進(jìn)行一系列初始化
refresh();
}
}
public ClassPathXmlApplicationContext(String path, Class<?> clazz) throws BeansException {
this(new String[] {path}, clazz);
}
public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz) throws BeansException {
this(paths, clazz, null);
}
public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, ApplicationContext parent)
throws BeansException {
super(parent);
Assert.notNull(paths, "Path array must not be null");
Assert.notNull(clazz, "Class argument must not be null");
this.configResources = new Resource[paths.length];
for (int i = 0; i < paths.length; i++) {
this.configResources[i] = new ClassPathResource(paths[i], clazz);
}
//調(diào)用父類的refresh函數(shù),進(jìn)行一系列初始化
refresh();
}
@Override
protected Resource[] getConfigResources() {
return this.configResources;
}
}到此這篇關(guān)于Spring中的ClassPathXmlApplicationContext源碼詳解的文章就介紹到這了,更多相關(guān)ClassPathXmlApplicationContext源碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java?file.delete刪除文件失敗,Windows磁盤出現(xiàn)無法訪問的文件問題
這篇文章主要介紹了Java?file.delete刪除文件失敗,Windows磁盤出現(xiàn)無法訪問的文件問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
springboot搭建訪客管理系統(tǒng)的實(shí)現(xiàn)示例
這篇文章主要介紹了springboot搭建訪客管理系統(tǒng)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Spring?Boot指標(biāo)監(jiān)控及日志管理示例詳解
Spring Boot Actuator可以幫助程序員監(jiān)控和管理SpringBoot應(yīng)用,比如健康檢查、內(nèi)存使用情況統(tǒng)計(jì)、線程使用情況統(tǒng)計(jì)等,這篇文章主要介紹了Spring?Boot指標(biāo)監(jiān)控及日志管理,需要的朋友可以參考下2023-11-11
SpringBoot + SpringSecurity 環(huán)境搭建的步驟
這篇文章主要介紹了SpringBoot + SpringSecurity 環(huán)境搭建的步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
十分簡單易懂的Java應(yīng)用程序性能調(diào)優(yōu)技巧分享
這篇文章主要介紹了十分簡單易懂的Java性能調(diào)優(yōu)技巧分享,具有一定參考價(jià)值,需要的朋友可以了解下。2017-11-11
MyBatis 參數(shù)類型為String時(shí)常見問題及解決方法
這篇文章主要介紹了MyBatis 參數(shù)類型為String時(shí)常見問題及解決方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03

