Jason ---分享,共同進步

          激情成就夢想,努力創造未來
          隨筆 - 53, 文章 - 1, 評論 - 45, 引用 - 0
          數據加載中……

          spring ApplicationContext簡單研究

          spring 研究裝載配置文件

          1,研究spring webApplicationContext初始化。spring 如何初始化。
          spring 有兩種方法,一個是ContextLoaderListener這個Listerner,另一個是ContextLoaderServlet這個Servlet,這兩個方法都是在web應用啟動的時候來初始化WebApplicationContext,ContextLoader是一個工具類,用來初始化WebApplicationContext,其主要方法就是initWebApplicationContext,ContextLoader是把WebApplicationContext(XmlWebApplicationContext是默認實現類)放在了ServletContext中,ServletContext也是一個“容器”,也是一個類似Map的結構,而WebApplicationContext在ServletContext中的KEY就是WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,我們如果要使用WebApplicationContext則需要從ServletContext取出,Spring提供了一WebApplicationContextUtils類,可以方便的取出WebApplicationContext,只要把ServletContext傳入就可以了。

          2,研究通過使用ApplicationContext對spring 進行初始化。

          初始化流程,在初始化的時候,新增一個加載servlet ,這個serlvet負責初始化。AppContextLoader 提供了初始化applicationContext的方法,
          通過定義ClassPathXmlApplicationContext 來加載spring 配置文件。裝載配置文件。
          并把裝載的ApplicationContext文件放在servletContext中作為全局變量來使用。在使用ClassPathXmlApplicationContext 則需要從ServletContext取出.

          posted on 2008-03-11 09:57 agun 閱讀(981) 評論(0)  編輯  收藏 所屬分類: java web

          主站蜘蛛池模板: 甘德县| 申扎县| 金门县| 永泰县| 东光县| 明水县| 九江市| 西乌珠穆沁旗| 图片| 观塘区| 五华县| 辽宁省| 清水县| 道孚县| 镇赉县| 巴里| 遂宁市| 姜堰市| 花莲县| 会昌县| 宜宾市| 长治县| 濉溪县| 咸宁市| 年辖:市辖区| 海口市| 陕西省| 堆龙德庆县| 长治市| 阜城县| 河北省| 桦川县| 武义县| 长岛县| 中牟县| 阜阳市| 墨江| 子长县| 庆云县| 文安县| 洪雅县|