前言

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实现容器的基本实现的更多相关文章

  1. spring源码分析系列 (3) spring拓展接口InstantiationAwareBeanPostProcessor

    更多文章点击--spring源码分析系列 主要分析内容: 一.InstantiationAwareBeanPostProcessor简述与demo示例 二.InstantiationAwareBean ...

  2. spring源码分析系列 (5) spring BeanFactoryPostProcessor拓展类PropertyPlaceholderConfigurer、PropertySourcesPlaceholderConfigurer解析

    更多文章点击--spring源码分析系列 主要分析内容: 1.拓展类简述: 拓展类使用demo和自定义替换符号 2.继承图UML解析和源码分析 (源码基于spring 5.1.3.RELEASE分析) ...

  3. spring源码分析系列 (1) spring拓展接口BeanFactoryPostProcessor、BeanDefinitionRegistryPostProcessor

    更多文章点击--spring源码分析系列 主要分析内容: 一.BeanFactoryPostProcessor.BeanDefinitionRegistryPostProcessor简述与demo示例 ...

  4. spring源码分析系列 (2) spring拓展接口BeanPostProcessor

    Spring更多分析--spring源码分析系列 主要分析内容: 一.BeanPostProcessor简述与demo示例 二.BeanPostProcessor源码分析:注册时机和触发点 (源码基于 ...

  5. spring源码分析系列3:BeanFactory核心容器的研究

    目录 @(spring源码分析系列3:核心容器的研究) 在讲容器之前,再明确一下知识点. BeanDefinition是Bean在容器的描述.BeanDefinition与Bean不是一个东西. Be ...

  6. 【Spring源码分析系列】结构组成和容器的基本实现

    beans包的层级结构 src/main/java:用于展现Spring的主要逻辑 src/main/resources:用于存放系统的配置文件 src/test/java:用于对主要逻辑单元进行测试 ...

  7. spring源码分析系列

    spring源码分析系列 (1) spring拓展接口BeanFactoryPostProcessor.BeanDefinitionRegistryPostProcessor spring源码分析系列 ...

  8. spring源码分析系列 (8) FactoryBean工厂类机制

    更多文章点击--spring源码分析系列 1.FactoryBean设计目的以及使用 2.FactoryBean工厂类机制运行机制分析 1.FactoryBean设计目的以及使用 FactoryBea ...

  9. spring源码分析系列 (15) 设计模式解析

    spring是目前使用最为广泛的Java框架之一.虽然spring最为核心是IOC和AOP,其中代码实现中很多设计模式得以应用,代码看起来简洁流畅,在日常的软件设计中很值得借鉴.以下是对一些设计模式的 ...

  10. Spring源码分析(十九)容器的功能扩展概览

    摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 经过前面几章的分析,相信大家已经对 Spring 中的容器功能有了简单 ...

随机推荐

  1. LCL Socket基类

    SocketBase类库主要是方便创建Socket客户端和Socket服务端的基础实现. 抽象基类:主要实现创建Socket public abstract class NetworkBase{} 通 ...

  2. 每天一个linux命令:ifconfig命令 临时修改重启后恢复原样

    许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...

  3. ASM实例原始磁盘搜索路径

    discovery diskstring==>ASM实例原始磁盘搜索路径,一般搜索/dev/raw/  /dev/oracleasm/ 初始化参数文件中为:asm_diskstring asmc ...

  4. mysql 字段区分大小写

    默认情况下, mysql中的字段是不区分大小写的,所以"aa"与"AA"被认为是一样的. 那么有些特殊情况下,我们希望它区分大小写呢,这时应该怎么办,说出来其实 ...

  5. android中YUV转RGB的方法

    在一个外国网站上看到一段YUV转RGB的程序很不错,根据维基上的知识,方法应该是没问题的,自己也用过了,效果没问题. 首先说一下android上preview中每一帧的信息都是YUV420的,或者叫N ...

  6. 快速排查SQL服务器阻塞语句

    SELECT*FROM sys.sysprocesses and blocked> --可以查看阻塞 SELECT SPID=p.spid, DBName =convert(CHAR(),d.n ...

  7. 复习js

    js写在页面最后如果放在前面,需要加window.onload=function(){)常见的两种输出方式 在网页中弹出显示框,显示信息 alert() 在控制台输出消息,一般用来调试程序consol ...

  8. Layui:设置select下拉框自动选中某项

    1.问题:layUI,在做编辑功能有下拉框数据时,需要初始化选中某个值,layUI官网没有相关api,可能我比较笨没找到 2.解决思路:出发点击事件 3.分析dom树结构,出发dl点击事件 方法: v ...

  9. 【函数式】Monads模式初探——for解析式

    for表达式是monad语法糖 先看一组演示样例: case class Person(name: String, isMale: Boolean, children: Person*) val la ...

  10. exchange 2003配置ASSP 反垃圾邮件

    Exchange上第三方反垃圾邮件用得比较多的是ORF,它直接运行在虚拟SMTP服务上,配置非常的方便.ASSP(https://sourceforge.net/projects/assp/) 是一个 ...