Java學(xué)習(xí)

          java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經(jīng)搬家了,新的地址是 http://www.javaly.cn 如果有對(duì)文章有任何疑問(wèn)或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂(lè)園)指出,我會(huì)盡力幫助解決。一起進(jìn)步

           

          Spring獲取Bean的幾種方式

          通過(guò)xml配置文件

              bean配置在xml里面,spring提供兩種方式讀取配置文件得到ApplicationContext.

          FileSystemXmlApplicationContext

              通過(guò)程序在初始化的時(shí)候,導(dǎo)入Bean配置文件,然后得到Bean實(shí)例:
          ApplicationContext oAC = new FileSystemXmlApplicationContext”applicationContext.xml”)
          oAC .getBean(”bean01″);

          WebApplicationContextUtil

               在B/S系統(tǒng)中,通常在web.xml初始化bean的配置文件,然后由WebAppliCationContextUtil得到ApplicationContext.例如:
          ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc);
          //ApplicationContext ctx =  WebApplicationContextUtils.getWebApplicationContext(ServletContext sc);
          getRequiredWebApplicationContext和 getWebApplicationContext的區(qū)別是,獲取失敗時(shí)候,getRequiredWebApplicationContext拋出異 常,getWebApplicationContext拋出null

          ApplicationObjectSupport

              抽象類,它提供getApplicationContext()方法,可以方便的獲取到ApplicationContext。Spring初始化時(shí),會(huì) 通過(guò)該抽象類的setApplicationContext(ApplicationContext context)方法將ApplicationContext 對(duì)象注入。

          WebApplicationObjectSupport

            抽象類,它提供getWebApplicationContext()獲WebApplicationContext

          ApplicationContextAware

            接口類,實(shí)現(xiàn)該接口的setApplicationContext(ApplicationContext context)方法,并保存ApplicationContext 對(duì)象。Spring初始化時(shí),會(huì)通過(guò)該方法將ApplicationContext對(duì)象注入。

          posted on 2008-10-16 11:21 找個(gè)美女做老婆 閱讀(2539) 評(píng)論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          公告

          本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
           http://www.javaly.cn

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 四会市| 绍兴市| 沅陵县| 枝江市| 平阴县| 道真| 嘉兴市| 都匀市| 唐山市| 镶黄旗| 吉林市| 运城市| 句容市| 安吉县| 德清县| 娄烦县| 昌黎县| 榕江县| 上栗县| 柳林县| 来宾市| 洞头县| 天峻县| 保康县| 平谷区| 尤溪县| 芒康县| 高淳县| 武冈市| 甘泉县| 吴江市| 濮阳市| 丹凤县| 西藏| 芜湖县| 三明市| 新密市| 昆山市| 罗源县| 广德县| 东光县|