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......餘下全文>>