隨筆 - 4  文章 - 10  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          spring為ApplicationContext提供的3種實現分別為:ClassPathXmlApplicationContext,FileSystemXmlApplicationContext和XmlWebApplicationContext,其中XmlWebApplicationContext是專為Web工程定制的。使用舉例如下:
             1. FileSystemXmlApplicationContext
                 eg1. ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); //加載單個配置文件
                 eg2.
                         String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
                         ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加載單個配置文件
                 eg3.    

              ApplicationContext ctx =new FileSystemXmlApplicationContext("D:/project/bean.xml");//根據具體路徑加載文件
            2. ClassPathXmlApplicationContext
                 eg1.  ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");
                 eg2.
                         String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
                         ApplicationContext ctx = new ClassPathXmlApplication(locations);
                 注:其中FileSystemXmlApplicationContext和ClassPathXmlApplicationContext與BeanFactoryxml文件定位方式一樣是基于路徑的。
           3. XmlWebApplicationContext
             eg1. ServletContext servletContext = request.getSession().getServletContext();    
                  ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);

          posted on 2007-08-13 16:04 冬天出走的豬 閱讀(1241) 評論(0)  編輯  收藏 所屬分類: spring
          主站蜘蛛池模板: 万全县| 正安县| 嵊州市| 乐东| 中阳县| 仁布县| 黄冈市| 务川| 阜宁县| 合川市| 绥江县| 阿图什市| 浦东新区| 凤阳县| 抚远县| 西平县| 镇江市| 潞城市| 元江| 凭祥市| 山东省| 锦州市| 丹凤县| 青岛市| 读书| 永福县| 山西省| 武隆县| 宁蒗| 龙岩市| 黎平县| 明水县| 静宁县| 五河县| 屏东市| 垣曲县| 平陆县| 内黄县| 江永县| 太康县| 宝丰县|