漁人碼頭

          天行健,君子以自強不息。地勢坤,君子以厚德載物。
          posts - 12, comments - 16, trackbacks - 0, articles - 43
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Spring中ApplicationContext加載機制

          Posted on 2006-12-26 15:48 Fisher 閱讀(679) 評論(0)  編輯  收藏 所屬分類: Spring
          Spring中ApplicationContext加載機制。
          ????加載器目前有兩種選擇:ContextLoaderListener和ContextLoaderServlet。
          ????這兩者在功能上完全等同,只是一個是基于Servlet2.3版本中新引入的Listener接口實現,而另一個基于Servlet接口實現。開發中可根據目標Web容器的實際情況進行選擇。

          配置非常簡單,在web.xml中增加:
          <listener>
          ??<listener-class>
          ???????org.springframework.web.context.ContextLoaderListener
          ??</listener-class>
          </listener>
          或:
          <servlet>
          ????<servlet-name>context</servlet-name>
          ????<servlet-class>
          ???????org.springframework.web.context.ContextLoaderServlet
          ????</servlet-class>
          ????<load-on-startup>1</load-on-startup>
          </servlet>

          通過以上配置,Web容器會自動加載/WEB-INF/applicationContext.xml初始化
          ApplicationContext實例,如果需要指定配置文件位置,可通過context-param加以指定:
          <context-param>
          ????<param-name>contextConfigLocation</param-name>
          ????<param-value>/WEB-INF/myApplicationContext.xml</param-value>
          </context-param>

          配置完成之后,即可通過
          ?WebApplicationContextUtils.getWebApplicationContext方法在Web應用中獲取ApplicationContext引用。

          如:ApplicationContext?ctx=WebApplicationContextUtils.getWebApplicationContext();
          ????LoginAction?action=(LoginAction)ctx.getBean("action");


          轉載:http://hi.baidu.com/jgs80/blog/item/307a40a794a7ad95d1435896.html

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 察隅县| 大悟县| 上饶县| 舞钢市| 绥江县| 新竹市| 双柏县| 黔西县| 镇平县| 武陟县| 嫩江县| 海林市| 伊宁县| 广汉市| 普安县| 丰镇市| 盐边县| 抚顺县| 仁化县| 沧州市| 扬中市| 都匀市| 高雄县| 根河市| 菏泽市| 花莲县| 翼城县| 饶平县| 岑巩县| 桑植县| 荔波县| 永登县| 子洲县| 会宁县| 邢台市| 察雅县| 云浮市| 福建省| 磐安县| 繁峙县| 丹寨县|