Spring源碼由淺入深系列六 CreateBean過程,springcreatebean

來源:互聯網
上載者:User

Spring源碼由淺入深系列六 CreateBean過程,springcreatebean

blog宗旨:用圖說話.

這一章的圖講述了createBean的過程。到這裡spring容器就可以完成IOC的整個過程,拿到我們需要的對象。

下一章我們接著來看一看AOP完成的過程。


附:目錄

Spring源碼由淺入深系列五 GetBean

Spring源碼由淺入深系列四 建立BeanFactory

Spring源碼由淺入深系列三 refresh

Spring源碼由淺入深系列二 類結構

Spring源碼由淺入深系列一 簡介



Spring的建立多個同一個類的bean,作為另一個bean中Map的值?

把bean 設定成不是單利的就可以了
scope="prototype"
 
spring 3源碼解析之怎解析"import", "alias", "bean"標籤

解析的步驟:1、載入web.xml、載入監聽器<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>2、ContextLoaderListener 初始化initWebApplicationContext方法建立org.springframework.web.context.support. XmlWebApplicationContext對象3、XmlWebApplicationContext調用loadBeanDefinitions方法,該方法主要做兩件事情:初始化XmlBeanDefinitionReader、擷取applicationContext.xml設定檔的路徑、然後把事情交給XmlBeanDefinitionReader來處理4、XmlBeanDefinitionReader擷取到applicationContext.xml設定檔的路徑、讀取設定檔的內容得到一個輸入資料流、對輸入資料流轉碼操作、然後封裝成一個inputSource對象、再然後封裝成一個document對象;在產生document對象的同事也產生了一個Resource對象、這兩個對象分部是:document對象承載設定檔的主要內容資訊、Resource承載設定檔的描述資訊以及一些驗證資訊。再由Resource對象建立一個XmlReaderContext。完成了以上操作XmlBeanDefinitionReader就把document對象和XmlReaderContext對象交給DefaultBeanDefinitionDocumentReader來處理5、DefaultBeanDefinitionDocumentReader1)、對XmlReaderContext裝飾成一個BeanDefinitionParserDelegate對象;2)、迭代document對象、把document對象拆分成Element元素逐個逐個解析;3)、使用BeanDefinitionParserDelegate裝飾對象解析Element元素或者說標籤。 if (absoluteLocation) { try { int importCount = getReaderContext().getReader().loadBeanDefinitions(location, actualResources); if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from URL location [" + location + "]"); } } catch (BeanDefinitionStoreException ex) { getReaderContext().error( "Failed to import bean definitions from URL location [" + location + "]", ele, ex); } } else { // No URL -> considering resource location as relative......餘下全文>>
 

聯繫我們

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