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:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
模拟spring的xml配置文件注入对象,里面用saxbuilder来解析xml文件。
在Spring框架中,开发者可以通过配置文件或注解的方式,定义和管理应用程序中的对象及其依赖关系。这使得对象之间的耦合度降低,提高了代码的可维护性和可扩展性。同时,Spring还提供了强大的事务管理、数据访问、...
我们首先要能够解析配置文件中的信息,然后建立包含相关信息的对象。最后根据这些信息利用反射机制完成对象的创建。首先我们看一下配置文件所包含的内容: , MainApp" /> typeName="IocInCSharp...
Spring的web框架包括可配置的处理器(handler)映射、视图(view)解析、本地化(local)解析、主题(theme)解析以及对上传文件解析。处理器是对Controller接口的实现,该接口仅仅定义了ModelAndView handleRequest...
2、Spring配置文件及其相应API 3、Spring注解开发 4、Spring web环境及其Junit的集成 5、Spring JDBCTemplate的基本使用 6、Spring AOP的介绍及其配置使用 7、Spring的声明式事务控制 8、SpringMVC的介绍及其快速...
(3)创建一个 spring mvc 的配置文件 (4)在 spring mvc 的配置文件中进行相关配置 1) 配置注解扫描路径 2)配置处理器映射器 3)配置处理器适配器 4)配置视图解析器 (5)开发 Controller
Spring框架是Java开发中广泛使用的一个强大工具,它通过依赖注入和控制反转等核心概念,极大地提高了开发效率和应用的可维护性。在这份文档中,我们深入探讨了Spring的核心注解,包括但不限于@Component、@...
【源码】mysql版本_spring3.0 系统模块 1. 组织管理:角色管理,分角色组和成员,有组权限和成员权限。 2. 系统用户:对各个基本的组会员增删改查,单发、群发邮件短信,导入导出excel表格,批量删除 3. 会员管理:...
SpringBoot+Mybatis+SpringSecurity+Bootstrap+Layui开发java web轻量级小巧视频...使用maven管理,采用maven进行项目的jar包管理,请使用maven工具根据pom文件配置阿里云仓库(vrps-sply/settings_sply.xml)自行下载
本项目使用前端技术结合easyUI,后端使用spring+springmvc+mybatis,log4j日志文件配置(带注释解析)
n 高级特性-自定义PropertySourceFactory实现解析yaml配置文件 n 源码分析-BeanFactory类视图和常用工厂说明 n 源码分析-AnnotationConfigApplicationContext的register方法 n 源码分析-...
.ioc底层原理使用技术 (1)xml配置文件 (2)dom4j解析xml (3)工厂设计模式 (4)反射
假如今天配置新的一个组件,称之为文件解析器,再点上传的时候,控制器会调用文件解析器,文件解析器可以帮助我们解析请求,解析request,解析完request,可以拿到上传文件项,就可以返回一个upload。后面继续执行...
第2篇是MyBatis技术入门,包括剖析JDBC的弊端、MyBatis的背景介绍、入门程序的编写、配置文件的剖析、高级映射及缓存结构的讲解,最后还介绍了MyBatis与Spring框架的整合。第3篇是Spring MVC技术入门,包括Spring ...
实现文件上传的思路: 1、创建form表单,...3、在SpringMVC配置文件中加入文件上传的解析器配置:CommonsMultipartReslover,id要严格写死:multipartReslover。 4、引入文件上传的相关依赖:commons-fileupload
Spring Cloud简介 Spring Cloud包含了多个子项目(针对分布式系统中涉及的多个不同开源产品),比如:Spring Cloud Config、Spring Cloud Netflix、Spring Cloud0 CloudFoundry、Spring Cloud AWS、Spring Cloud ...
1.6 Spring Boot使用别的json解析框架 1.7 全局异常捕捉 1.8 Spring Boot datasource - mysql 1.9 JPA - Hibernate 1.10 使用JPA保存数据 1.11 使用JdbcTemplate 1.12 Spring Boot修改端口号 1.13 Spring Boot配置...