`
JerryWang_SAP
  • 浏览: 957988 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

一个快速找到Spring框架是在哪里找到XML配置文件并解析Beans定义的小技巧

阅读更多

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/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://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:

 

 

 

0
1
分享到:
评论

相关推荐

    spring配置文件:整理总结Spring中XML配

    文件中进行了详细介绍说明这个配置文件是典型XML格式但是它既冗长又不实用对于需要定义大量 Springbeans大工程来说我们难以阅读和管理它  在这篇文章里对于SpringXML配置我将向你展示12种比较好实战其中些实战不仅...

    Spring XML配置的12个技巧

    Spring beans,依赖关系,以及服务所需要的bean都将在配置文件中予以描述,配置文件一般采用XML格式。 然而XML配置文件冗长而不易使用,在你进行一个使用了大量bean的大项目中它将变得难以阅读和控制。

    Spring项目主配置文件

    初学Spring的小伙伴,还在为找不到主配置文件而着急吗,该配置文件是基于Spring4.10版本的,不用再自己到官网页面上到处找了,分享给大家,也希望大家别再像我一样因为这个坑耽误了大半天的时间,如果要自己配置也...

    配置文件生成器spring-beans-writer.zip

    spring-beans-writer用来生成spring IOC的配置文件,可以自动写入简单类型以及List、Map等复杂类型的值。示例如下:SpringBeans beans = new SpringBeans();  beans.addBean(_database, "database");  ...

    spring-beans.zip

    在bean tag中有个属性”singleton”,如果它被赋为TRUE,bean 就是单件,否则就是一个 prototype bean。默认是TRUE,所以所有在Spring框架中的beans 缺省都是单件。包含:spring-beans-5.2.0.RELEASE.jarspring-...

    spring框架配置bean的高级属性

    关键就在于配置文件,下面看一个样例app.xml: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

    spring框架约束步骤及教程

    spring-beans.jar 这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI支持,引入...

    spring-beans.jar

    org.springframework.beans-2.5.5.A.jar, org.springframework.beans-2.5.6.A.jar, org.springframework.beans-2.5.6.SEC01.jar, org.springframework.beans-3.0.0.M1.jar, org.springframework.beans-3.0.0.M2.jar,...

    spring配置文件xml不给提示

    spring配置文件xml不给提示怎么办,在配置之前先下载spring-beans-2.5.xsd

    springmvc-config.xml

    这是一个springmvc-config.xml文件,&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" ...

    spring-beans-5.2.0.RELEASE-API文档-中文版.zip

    赠送jar包:spring-beans-5.2.0.RELEASE.jar; 赠送原API文档:spring-beans-5.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-beans-5.2.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-beans-5.2.0....

    spring-beans-4.2xsd 文件下载

    Spring默认在启动时是要加载XSD文件来验证xml文件的,所以如果有的时候断网了,或者一些开源软件切换域名,那么就很容易碰到应用启动不了。我记得当时Oracle收购Sun公司时,遇到过这个情况。为了防止这种情况,...

    spring-beans-5.0.10.RELEASE-API文档-中文版.zip

    赠送jar包:spring-beans-5.0.10.RELEASE.jar; 赠送原API文档:spring-beans-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-beans-5.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-beans-5.0.10....

    spring配置文件解析失败报”cvc-elt.1: 找不到元素 &#39;&#39;beans&#39;&#39; 的声明”异常解决

    主要给大家介绍了关于spring配置文件解析失败报”cvc-elt.1: 找不到元素 'beans' 的声明”异常的解决方法,需要的朋友可以参考下

    Spring XML 配置扩展机制

    &lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans ...

    spring-beans-5.2.0.RELEASE-API文档-中英对照版.zip

    赠送jar包:spring-beans-5.2.0.RELEASE.jar; 赠送原API文档:spring-beans-5.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-beans-5.2.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-beans-5.2.0....

    spring-beans.dtd

    在eclipose 中引入spring-beans.dtd 可以在不联网的时候编辑XML自动提示

    spring-beans-5.3.7-API文档-中英对照版.zip

    赠送jar包:spring-beans-5.3.7.jar; 赠送原API文档:spring-beans-5.3.7-javadoc.jar; 赠送源代码:spring-beans-5.3.7-sources.jar; 赠送Maven依赖信息文件:spring-beans-5.3.7.pom; 包含翻译后的API文档:...

    spring beans jar

    spring beans jar包,需要另外3个包。加上log4j和logging

Global site tag (gtag.js) - Google Analytics