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這些類,凡是配置文件寫全類名的都這樣。哪些文件都是當參數傳進去,或放在固定地方。
          主站蜘蛛池模板: 防城港市| 禹城市| 莆田市| 淮阳县| 四平市| 开封县| 龙州县| 巴林右旗| 屯留县| 夏津县| 托克托县| 洞头县| 清徐县| 策勒县| 莱阳市| 灌云县| 盐亭县| 政和县| 镇安县| 文昌市| 阿克苏市| 开平市| 北票市| 秭归县| 晋州市| 和林格尔县| 永定县| 旌德县| 久治县| 紫阳县| 商洛市| 秀山| 娱乐| 张家川| 阿尔山市| 文化| 台南市| 新野县| 南乐县| 兴和县| 库车县|