Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
          spring為ApplicationContext提供的3種實現分別為:ClassPathXmlApplicationContext, FileSystemXmlApplicationContext和XmlWebApplicationContext,其中 XmlWebApplicationContext是專為Web工程定制的。使用舉例如下:
             1. FileSystemXmlApplicationContext
               
          Java代碼 復制代碼
          1. eg1.   
          2. pplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); //加載單個配置文件  
           eg1.
          ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); //加載單個配置文件

               
          Java代碼 復制代碼
          1. eg2.   
          2. String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};   
          3. ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加載多個配置文件  
          eg2.
          String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
          ApplicationContext ctx = new FileSystemXmlApplicationContext(locations ); //加載多個配置文件

                
          Java代碼 復制代碼
          1. eg3.       
          2. ApplicationContext ctx =new FileSystemXmlApplicationContext("D:roject/bean.xml");//根據具體路徑加載文件  
          eg3.
          ApplicationContext ctx =new FileSystemXmlApplicationContext("D:roject/bean.xml");//根據具體路徑加載文件

            2. ClassPathXmlApplicationContext
               
          Java代碼 復制代碼
          1. eg1.     
          2. pplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");  
           eg1.
          ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");

               
          Java代碼 復制代碼
          1.  eg2.   
          2. String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};   
          3. ApplicationContext ctx = new ClassPathXmlApplication(locations);   
          4. 注:其中FileSystemXmlApplicationContext和ClassPathXmlApplicationContext與BeanFactory的xml文件定位方式一樣是基于路徑的。  
           eg2.
          String[] locations = {"bean1.xml", "bean2.xml", "bean3.xml"};
          ApplicationContext ctx = new ClassPathXmlApplication(locations);
          注:其中FileSystemXmlApplicationContext和ClassPathXmlApplicationContext與BeanFactory的xml文件定位方式一樣是基于路徑的。

          3. XmlWebApplicationContext
          Java代碼 復制代碼
          1. eg1.   
          2. ServletContext servletContext = request.getSession().getServletContext();       
          3. ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); 
          posted on 2010-02-02 14:28 seal 閱讀(267) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 绵阳市| 威信县| 咸阳市| 富锦市| 红安县| 宜黄县| 永福县| 涿州市| 龙口市| 辉县市| 泸州市| 抚宁县| 三明市| 尚志市| 阿城市| 修水县| 嫩江县| 来凤县| 铜鼓县| 饶河县| 财经| 三亚市| 潍坊市| 靖州| 广宁县| 杭州市| 和硕县| 六枝特区| 安溪县| 察隅县| 璧山县| 辽宁省| 荣成市| 乐东| 金寨县| 远安县| 从化市| 江达县| 大名县| 西城区| 诸城市|