BeanFactory和ApplicationContext有什麼區別?

來源:互聯網
上載者:User

標籤:files   xmla   ext   自身   context   設定檔   客戶   國際化   之間   

BeanFactory 可以理解為含有bean集合的工廠類。BeanFactory 包含了種bean的定義,以便在接收到用戶端請求時將對應的bean執行個體化。
BeanFactory還能在執行個體化對象的時產生協作類之間的關係。此舉將bean自身與bean用戶端的配置中解放出來。BeanFactory還包含了bean生命週期的控制,調用用戶端的初始化方法(initialization methods)和銷毀方法(destruction methods)。
從表面上看,application context如同bean factory一樣具有bean定義、bean關聯關係的設定,根據請求分發bean的功能。但application context在此基礎上還提供了其他的功能。

  1. 提供了支援國際化的簡訊
  2. 統一的資源檔讀取方式
  3. 已在監聽器中註冊的bean的事件
    以下是三種較常見的 ApplicationContext 實現方式:
    1、ClassPathXmlApplicationContext:從classpath的XML設定檔中讀取上下文,並產生上下文定義。應用程式上下文從程式環境變數中取得。
    ApplicationContext context = new ClassPathXmlApplicationContext(“bean.xml”);
    2、FileSystemXmlApplicationContext :由檔案系統中的XML設定檔讀取上下文。
    ApplicationContext context = new FileSystemXmlApplicationContext(“bean.xml”);
    3、XmlWebApplicationContext:由Web應用的XML檔案讀取上下文。

BeanFactory和ApplicationContext有什麼區別?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.