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 閱讀(261) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 丰原市| 皮山县| 蕲春县| 太和县| 南丹县| 大港区| 务川| 钦州市| 博罗县| 遵化市| 华蓥市| 晋江市| 平果县| 长宁区| 诸城市| 潮安县| 岐山县| 延津县| 东安县| 忻城县| 大余县| 泗阳县| 舟山市| 瓦房店市| 滨海县| 榆树市| 盐津县| 孟村| 南丹县| 东丽区| 桓台县| 高雄市| 枞阳县| 芒康县| 将乐县| 丽江市| 屏边| 江山市| 濮阳县| 内江市| 甘孜|