Spring框架裡解析配置檔案的準確位置
We can define bean configuration in xml and then can get instantiated bean instance with help of all kinds of containers for example ClassPathXmlApplicationContext as displayed below:
The content of Beans.xml:
<?xml version="1.0" encoding="UTF-8"?><!-- http://stackoverflow.com/questions/18802982/no-declaration-can-be-found-for-element-contextannotation-config --><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd">
<bean id="helloWorld" class="main.java.com.sap.HelloWorld">
<property name="message" value="sss"/>
<property name="testMin" value="2"/>
<property name="phone" value="1"/>
</bean></beans>
Where can we set breakpoint to start? No hint. Here is a tip: we can make the Beans.xml invalid by deliberately changing te tag bean to beana, and relaunch application. Now exception is raised as expected: Click the hyperlink XmlBeanDefinitionReader.java:399,
The line 399 where exception is raised will be automatically located. The core logic to load xml file is just near the exception raise position: line 391. So we can set breakpoint in line 391 now:
Change the tag from beana back to bean, and start application via debug mode. The code below is the core logic of Bean configuration file parse in Spring framework. The logic consists of two main steps:
(1) parse XML as a dom structure in memory ( line 391 ) (2) extract bean information contained in dom structure and generate BeanDefinition structure ( line 392 )
from screenshot below we can find out the xml is parsed via SAX parser:
My “helloWorld” bean is parsed here:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2724092/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Spring系列之手寫註解與配置檔案的解析Spring
- MySQL 配置檔案位置及命名。MySql
- 正確映象檔案配置
- Spring Boot 框架中配置檔案 application.properties 當中的所有配置大全Spring Boot框架APP
- Benchmarksql的props配置檔案解析SQL
- 深入解析 Spring 配置檔案:從基礎到高階Spring
- Spring Boot 配置檔案Spring Boot
- Spring檔案最全配置Spring
- 如何將檔案放在正確位置?2020年的檔案傳輸解決方案
- Spring Boot @PropertySource 載入指定配置檔案、@ImportResource 匯入Spring 配置檔案Spring BootImport
- 原始碼解析Flask的配置檔案原始碼Flask
- SSM框架pom配置檔案SSM框架
- SSM框架整合(配置檔案)SSM框架
- DHCP常用配置檔案解析
- java解析yaml配置檔案JavaYAML
- Spring - 配置檔案中的特殊字元Spring字元
- Spring Boot的配置檔案管理技巧Spring Boot
- spring和Mybatis的核心配置檔案SpringMyBatis
- rabbitMQ-Spring配置檔案MQSpring
- 【SSM框架整合】專案xml檔案、properties等檔案的配置SSM框架XML
- Spring Boot乾貨系列:(二)配置檔案解析 | 掘金技術徵文Spring Boot
- 轉載:為什麼在 Spring 的配置裡,最好不要配置 xsd 檔案的版本號Spring
- win10搜尋檔案在哪裡 檢視搜尋檔案位置的方法Win10
- 文盤Rust -- 配置檔案解析Rust
- tidb-server 的配置檔案在哪裡?TiDBServer
- spring boot配置檔案相關Spring Boot
- Spring Boot 配置檔案總結Spring Boot
- SpringMvc+Spring+mybatis配置檔案SpringMVCMyBatis
- 精進 Spring Boot 03:Spring Boot 的配置檔案和配置管理,以及用三種方式讀取配置檔案Spring Boot
- ls命令統計檔案數量不準確
- SpringBoot原始碼解析-配置檔案的載入Spring Boot原始碼
- .Net Core中的配置檔案原始碼解析原始碼
- SpringBoot 如何解析配置檔案中的list?Spring Boot
- 乾貨分享之Spring框架原始碼解析01-(xml配置解析)Spring框架原始碼XML
- mybatis原始碼配置檔案解析之五:解析mappers標籤(解析XML對映檔案)MyBatis原始碼APPXML
- webpack配置檔案中屬性的位置和資料結構Web資料結構
- 快速準確搜尋檔案:HoudahSpot 中文啟用版
- Spring YAML與屬性檔案配置檔案對比 | BaeldungSpringYAML