漁人碼頭

          天行健,君子以自強(qiáng)不息。地勢(shì)坤,君子以厚德載物。
          posts - 12, comments - 16, trackbacks - 0, articles - 43
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          Spring中ApplicationContext加載機(jī)制

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

          配置非常簡(jiǎn)單,在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>

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

          配置完成之后,即可通過(guò)
          ?WebApplicationContextUtils.getWebApplicationContext方法在Web應(yīng)用中獲取ApplicationContext引用。

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


          轉(zhuǎn)載:http://hi.baidu.com/jgs80/blog/item/307a40a794a7ad95d1435896.html

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 仲巴县| 梨树县| 胶州市| 色达县| 漳浦县| 冕宁县| 库伦旗| 灵丘县| 桃江县| 宝山区| 抚顺市| 崇明县| 邵武市| 高阳县| 平乡县| 鄯善县| 合水县| 静宁县| 弥勒县| 平原县| 垣曲县| 定结县| 铜鼓县| 岢岚县| 揭东县| 芮城县| 华容县| 搜索| 绵竹市| 桃园县| 洛阳市| 宣威市| 葫芦岛市| 华安县| 柳江县| 万州区| 弥勒县| 那坡县| 汕尾市| 古丈县| 宜都市|