【Spring源码分析系列】搭建Spring实现容器的基本实现
前言
bean是Spring中最核心的东西,因为Spring就像一个大水桶,而bean就像是容器中的水,先新建一个小例子来看一下;
一、使用eclipse构建项目,项目结构如下

二、类文件内容
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd"> <bean id="car" class="com.slp.Car"></bean>
</beans>
package com.slp;
/**
*
* @ClassName: Car
* @Description:测试类
* @author: liping.sang
* @date: 2017年9月22日 上午8:55:37
*
* @Copyright: 2017 liping.sang Inc. All rights reserved.
*/
public class Car { private String speed = "200";
private String brandName = "BYD";
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
public String getBrandName() {
return brandName;
}
public void setBrandName(String brandName) {
this.brandName = brandName;
} }
package com.slp; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource; public class TestConfig { public static void main(String[] args) {
// TODO Auto-generated method stub
BeanFactory bf = new XmlBeanFactory(new ClassPathResource("beans.xml"));
Car car = (Car) bf.getBean("car");
System.out.println(car.getSpeed());//===>200
} }
三、功能分析
1、上述完成的功能
1)读取配置文件beans.xml
2)根据beans.xml中的配置找到对应的类的配置,并实例化
3)调用实例化后的实例

ConfigReader:用于读取及验证配置文件,我们要用配置文件里的内容,首先要读取,然后放入到内存中。
ReflectionUtil:用于根据配置文件中的配置进行反射实例化。
App:用于完成整个逻辑的串联。
【Spring源码分析系列】搭建Spring实现容器的基本实现的更多相关文章
- spring源码分析系列 (3) spring拓展接口InstantiationAwareBeanPostProcessor
更多文章点击--spring源码分析系列 主要分析内容: 一.InstantiationAwareBeanPostProcessor简述与demo示例 二.InstantiationAwareBean ...
- spring源码分析系列 (5) spring BeanFactoryPostProcessor拓展类PropertyPlaceholderConfigurer、PropertySourcesPlaceholderConfigurer解析
更多文章点击--spring源码分析系列 主要分析内容: 1.拓展类简述: 拓展类使用demo和自定义替换符号 2.继承图UML解析和源码分析 (源码基于spring 5.1.3.RELEASE分析) ...
- spring源码分析系列 (1) spring拓展接口BeanFactoryPostProcessor、BeanDefinitionRegistryPostProcessor
更多文章点击--spring源码分析系列 主要分析内容: 一.BeanFactoryPostProcessor.BeanDefinitionRegistryPostProcessor简述与demo示例 ...
- spring源码分析系列 (2) spring拓展接口BeanPostProcessor
Spring更多分析--spring源码分析系列 主要分析内容: 一.BeanPostProcessor简述与demo示例 二.BeanPostProcessor源码分析:注册时机和触发点 (源码基于 ...
- spring源码分析系列3:BeanFactory核心容器的研究
目录 @(spring源码分析系列3:核心容器的研究) 在讲容器之前,再明确一下知识点. BeanDefinition是Bean在容器的描述.BeanDefinition与Bean不是一个东西. Be ...
- 【Spring源码分析系列】结构组成和容器的基本实现
beans包的层级结构 src/main/java:用于展现Spring的主要逻辑 src/main/resources:用于存放系统的配置文件 src/test/java:用于对主要逻辑单元进行测试 ...
- spring源码分析系列
spring源码分析系列 (1) spring拓展接口BeanFactoryPostProcessor.BeanDefinitionRegistryPostProcessor spring源码分析系列 ...
- spring源码分析系列 (8) FactoryBean工厂类机制
更多文章点击--spring源码分析系列 1.FactoryBean设计目的以及使用 2.FactoryBean工厂类机制运行机制分析 1.FactoryBean设计目的以及使用 FactoryBea ...
- spring源码分析系列 (15) 设计模式解析
spring是目前使用最为广泛的Java框架之一.虽然spring最为核心是IOC和AOP,其中代码实现中很多设计模式得以应用,代码看起来简洁流畅,在日常的软件设计中很值得借鉴.以下是对一些设计模式的 ...
- Spring源码分析(十九)容器的功能扩展概览
摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 经过前面几章的分析,相信大家已经对 Spring 中的容器功能有了简单 ...
随机推荐
- 嵌入式开发之uart---编程
下位机往上位机发送串口数据都是漫漫的这个包,但是win上位机往下位机发数据时,得分包大小,下位机收到的不一从1到200左右,大部分为100左右 http://bbs.csdn.net/topics/3 ...
- ASP.NET后台输出js脚本代码
利用asp.net输出js我们大多数都会直接使用Respone.Write()然后根js格式的代码,再在页面调用时我们直接这样是完全可以实现的,下面我来给大家介绍另一种方法 我是我最初的想法以下是代码 ...
- Ironic 安装和配置详解
转自:http://amar266.blogspot.com/2014/12/ironic-installation-and-configuration.html 1.Install Openstac ...
- linux中crontab实战篇
1.先安装crontab,之前的文章有介绍 2.查看 crontab -l 3.编辑 crontab -e 0 7 * * * /application/php/bin/php www.xialan. ...
- UNIX环境编程学习笔记(16)——进程管理之进程环境变量
lienhua342014-10-03 1 环境表和环境指针 在每个进程启动时,都会接到一张环境表.环境表是一个字符指针数组,其中每个指针包含一个以 null 结束的 C 字符串的地址.全局变量env ...
- Oracle:在 debian9 上完美安装 oracle 10.2.0.5 x64
多余废话不说. 多动脑子,思路不要僵化. 关键点: --------------------------------------------------- 安装i386的支持库:libc6-dev:3 ...
- 提高OCR质量的技巧之区域未正确检测
ABBYY FineReader会在识别前分析页面图像并检测图片上不同类型的区域,如文本.图片.背景图片.表格和条形码区域,此分析确定识别的区域和识别顺序.在用户界面中,不同的区域类型按其边界的颜色进 ...
- PHP日期知识
(1)date用法: date(格式,[时间]);如果没有时间参数,则使用当前时间. 格式是一个字符串,其中以下字符有特殊意义:U 替换成从一个起始时间(好象是1970年1月1日)以来的秒数 Y 替换 ...
- ios 查看模拟器路径以及应用的文件夹
模拟器文件查看 好,这个时候选择往模拟器上面调试程序: 运行模拟器: 打开Finder,按住option,在菜单栏中选择“前往”->“资源库” 如果没发现资源库,则使用终端 命令行输入 ope ...
- 抓包工具Wireshark
https://baike.baidu.com/item/Wireshark/10876564?fr=aladdin