類比Spring容器的getBean方法(Maven工程)

來源:互聯網
上載者:User

標籤:png   構造   ngx   http   檔案配置   test   XML   pom   步驟   

Spring容器的getBean方法是通過反射機制實現的,下面的測試程式類比getBean的實現原理.

步驟一:pom.xml檔案配置解析XML檔案的dom4j.jar

步驟二:XML檔案中配置bean標籤

步驟三:建立測試類別ParseSpringXMLTest,設定成員屬性,由於bean標籤中沒有設定Scope屬性,故預設使用singleton建立單例.這裡建立一個Map集合儲存建立好的對象.

步驟四:建立構造器,初始化成員屬性

步驟五:類比實現getBean方法

步驟六:測試程式

步驟七:控制台輸出(完結散花..)

 

 

 

 

類比Spring容器的getBean方法(Maven工程)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.