Spring啟動並載入(原始碼解析)

2021-08-29 20:23:28 字數 1281 閱讀 7117

二、流程

contextconfiglocation

classpath:config/spring.xml

org.springframework.web.context.contextloaderlistener

package org.springframework.web.context;

public class contextloaderlistener extends contextloader implements servletcontextlistener

……}

package org.springframework.web.context;

public class contextloader else

……return this.context;

} catch (runtimeexception var8) catch (error var9) }}

……class<?> contextclass = this.determinecontextclass(sc);

} else }……

protected class<?> determinecontextclass(servletcontext servletcontext) catch (classnotfoundexception var4)

} else catch (classnotfoundexception var5) }}

……string configlocationparam;

……configlocationparam = sc.getinitparameter("contextconfiglocation");

……wac.refresh();}……

}

web.xml 中配置的spring***(contextloaderlistener)被載入並呼叫上下文初始化方法(public void contextinitialized(servletcontextevent event))

現在程式已經知道要以xml配置方式去載入spring上下文,那麼只剩下如何去讀取到web.xml中配置好的contextconfiglocation值得到xml鏈結並載入了。

spring容器和上下文的理解

spring原始碼分析之——spring bean的載入入口

sping提供了兩種型別的 ioc 容器實現.

spring基礎篇——spring容器和應用上下文理解

Spring載入過程原始碼分析

spring 載入過程 public void refresh throws bean ception,illegalstateexception catch bean ception var9 this.destroybeans this.cancelrefresh var9 throw var9...

spring原始碼分析 spring原始碼分析

1.spring 執行原理 spring 啟動時讀取應用程式提供的 bean 配置資訊,並在 spring 容器中生成乙份相應的 bean 配置登錄檔,然後根據這張登錄檔例項化 bean,裝配好 bean 之間的依賴關係,為上 層應用提供準備就緒的執行環境。二 spring 原始碼分析 1.1spr...

Spring原始碼解析之 資源載入(1)

關於資源載入。spring抽像了兩個介面。分別是 resource 和resourceloader,作用分別是 resource 所有資源的抽像和訪問介面 resourceloader 是用於定位和查詢resource的資源。配合resource來使用 通過resource 介面來擴充套件不同型別的...