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

          主站蜘蛛池模板: 阿瓦提县| 哈巴河县| 中牟县| 东乡县| 莱阳市| 正定县| 胶州市| 灵石县| 高邮市| 封丘县| 淮阳县| 民权县| 全州县| 商丘市| 大港区| 柳州市| 即墨市| 宿松县| 新巴尔虎右旗| 齐齐哈尔市| 晋中市| 青川县| 九台市| 香港| 天津市| 吉木乃县| 南通市| 盐源县| 集贤县| 饶平县| 铜陵市| 定边县| 武乡县| 南召县| 陆良县| 麟游县| 仁布县| 台南市| 特克斯县| 南郑县| 资兴市|