一、spring框架
1、基本框架

2、Beanfactory快速入门

配置清单:xml文件
(1) 导入jar包或者maven坐标
(2) 定义UserService接口以及UserService实现类
(3) 创建bean.xml配置文件,将UserService信息配置到该xml文件中;
(4)编写测试代码,创建BeanFactory,加载配置文件,获取UserService对象
①、示例代码1

DefaultListableBeanFactory : 工厂对象
XmlBeanDefinitionReader : 工厂对应的读取器,读取xml文件到工厂中
读取器对象.loadBeanDefinitions("xml文件") : 读取过程
工厂对象.getBean("bean对象对应id") : 得到id对应的class对象
②、示例代码2
配置xml

ref : 从xml文件中读取id相同的bean对象
name = 从本bean对象中读取调用名字是userDao的方法(javabean方法)
userDao可以代表了UserDao的get或者set方法,像getter和setter这些标准javabean方法
3.ApplicationContext快速入门(重点)
①、简单示例

封装BeanFactory的方法流程,从而简化流程
ClassPathXmlApplicationContext("xml文件") : 读取对象
ApplicationContext : 对象
对象.getBean("方法名") : 调用方法,并获取对应类
4、两者关系(区别)
①、联系概述

②、继承体系

二、基于xml的spring应用
1、springBean配置详解
①、基于xml的bean配置(1)

(1)、<bean id> 会转化成<bean name>进行存储。
(2)、如果没有id 和 name(别名) 的话,id默认值就是<bean class>中class的值。
(3)、id 与 name(别名) 同时存在时,首选id
(4)、Bean - scope 范围配置

singleton : 单例池 每次获取对象(getbean)都是从这里取 (对象地址不变)
prototype : 每次getbean时才创建(对象地址改变),不放入单例池。
(5)、Bean - lazy-init 延迟加载 (只对ApplicationContext有效, 对BeanFactory无效)

(6)、Bean的初始化和销毁方法

构造方法先执行,然后init()方法执行,
容器关闭的时候才会调用 destroy()方法,
容器关闭 : 对象.close()
(7) 、 InitializingBean实现接口

(8)、Bean的实例化配置

静态工厂方法:


-------------------无需创建对象,直接调用方法即可。
实例工厂方法:


------------------需要创建对象,然后调用方法。
配置Bean时有参数的配置:


上面两个执行结果一样,说明参数都可以通过<constructor - arg> 进行参数的传递。
<constructor - arg> 传递的参数都是用来构造Bean的, (上图)不管是static还是非static。
实现FactoryBean规范延迟实例化Bean:
回看黑马spring源码讲解的p22章节。
②、基于xml的bean配置(2)
1、Bean的依赖注入


集合数据类型配置示例:


Set 和Map方法与List相同类比。
autowire自动装配 :

③、xml的其它配置标签




2、spring的get方法

3、spring配置非自定义Bean

上图信息放到配置文件中就是 =====>

配置connection

配置Date

4、Bean实例化基本流程



5、spring后处理器

①、springBean工厂后处理器
流程图:

BeanFactoryPostProcessor - Bean工厂后处理器
②、spring的Bean后处理器
BeanPostProcessor - Bean后处理器

bean示例流程完整图

6、Spring Bean生命周期

初始化阶段:


循环依赖:

三级缓存:

Aware接口:

7、Spring Ioc 整体流程总结
