當前位置:編程學習大全網 - 源碼下載 - Spring源碼解析哪本書好

Spring源碼解析哪本書好

解析的步驟: 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 to the current file. try { int importCount; Resource relativeResource = getReaderContext().getResource().createRelative(location); if (relativeResource.exists()) { importCount = getReaderContext().getReader().loadBeanDefinitions(relativeResource); actualResources.add(relativeResource); } else { String baseLocation = getReaderContext().getResource().getURL().toString(); importCount = getReaderContext().getReader().loadBeanDefinitions( StringUtils.applyRelativePath(baseLocation, location), actualResources); } if (logger.isDebugEnabled()) { logger.debug("Imported " + importCount + " bean definitions from relative location [" + location + "]"); } } catch (IOException ex) { getReaderContext().error("Failed to resolve current resource location", ele, ex); } catch (BeanDefinitionStoreException ex) { getReaderContext().error("Failed to import bean definitions from relative location [" + location + "]", ele, ex); } } Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]); getReaderContext().fireImportProcessed(location, actResArray, extractSource(ele)); } 解析alias標簽的方法:

  • 上一篇:股票軟件中SCR指標的數據是什麽意思?
  • 下一篇:我要學漫畫!!!!
  • copyright 2024編程學習大全網