posts - 82, comments - 269, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Spring在Web中是如何載入相關的上下文環境

          Posted on 2006-12-21 21:00 itspy 閱讀(2934) 評論(5)  編輯  收藏 所屬分類: JAVA技術

          ?在web.xml設置監聽器:org.springframework.web.context.ContextLoaderListener
          ?<listener>
          ??<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          ?</listener>
          ?
          ?在此類(ContextLoaderListener)中有如下方法:?
          ?public void contextInitialized(ServletContextEvent event) {
          ??this.contextLoader = createContextLoader();
          ??this.contextLoader.initWebApplicationContext(event.getServletContext());
          ?}
          ?
          ?org.springframework.web.context.ContextLoader
          ?在此類中有如下變量:?public static final String CONTEXT_CLASS_PARAM = "contextClass";
          ????public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation";

          ?
          ?如下方法:initWebApplicationContext,createWebApplicationContext
          ?第一個方法調用了第二個方法,第二個方法則通過如下代碼初始為了一個上下文環境
          ?String configLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
          ?
          ?注:另外一點如下的DispatcherServlet設置會自動加載petstore-servlet.xml環境,原理我查了半天我也不知道怎么搞的.
          ?<servlet>
          ??<servlet-name>petstore</servlet-name>
          ??<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          ??<load-on-startup>2</load-on-startup>
          ?</servlet>


          評論

          # re: Spring在Web中是如何載入相關的上下文環境  回復  更多評論   

          2006-12-22 08:22 by 壞男孩
          頂!??

          # re: Spring在Web中是如何載入相關的上下文環境  回復  更多評論   

          2006-12-22 09:34 by BeanSoft
          哈哈, 把源碼都查找一遍就 OK 了.

          # re: Spring在Web中是如何載入相關的上下文環境  回復  更多評論   

          2006-12-22 13:09 by xmlspy
          另外一點如下的DispatcherServlet設置會自動加載petstore-servlet.xml環境,原理我查了半天我也不知道怎么搞的.


          原因:

          spring默認加載 你的工程名稱-servlet.xml 文件,

          # re: Spring在Web中是如何載入相關的上下文環境  回復  更多評論   

          2006-12-22 19:15 by itspy
          @xmlspy


          spring默認加載 你的工程名稱-servlet.xml 文件

          這個我知道,我是想看看實現這段功能的代碼,但沒找到.

          # re: Spring在Web中是如何載入相關的上下文環境  回復  更多評論   

          2006-12-28 15:01 by baal
          其實都是classload,app server會在啟動時去先load這些類,凡是配置文件寫全類名的都這樣。哪些文件都是當參數傳進去,或放在固定地方。
          主站蜘蛛池模板: 武城县| 顺昌县| 兴海县| 天水市| 浮梁县| 调兵山市| 综艺| 营口市| 永和县| 正定县| 商南县| 峨眉山市| 林芝县| 衡南县| 汉川市| 武义县| 拜城县| 宜阳县| 辽宁省| 云阳县| 阳高县| 祁阳县| 哈巴河县| 五华县| 武威市| 新沂市| 洛扎县| 长白| 大庆市| 韶山市| 苗栗县| 岢岚县| 上饶县| 株洲市| 波密县| 韶山市| 东乡县| 团风县| 株洲县| 河曲县| 民乐县|