|
@@ -0,0 +1,56 @@
|
|
|
+# Spring IoC依赖来源
|
|
|
+
|
|
|
+## 1. 依赖查找的来源
|
|
|
+
|
|
|
+查找来源
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+Spring 內建 BeanDefintion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+Spring 內建单例对象
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## 2. [依赖注入](https://so.csdn.net/so/search?q=依赖注入&spm=1001.2101.3001.7020)的来源
|
|
|
+
|
|
|
+注入来源
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+* 单例对象由 `org.springframework.beans.factory.config.SingletonBeanRegistry` 注册,`org.springframework.beans.factory.support.AbstractBeanFactory` 实现了这个接口,从容器中获取 Bean 的方法 `org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean` 中,会先从单例对象中查找,如果查找到,直接返回;查找不到,则从 Spring BeanDefinition 中获取,并**执行生命周期函数**
|
|
|
+
|
|
|
+## 3. Spring 容器管理和游离对象
|
|
|
+
|
|
|
+* 依赖对象
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## 4. Spring BeanDefinition 作为依赖来源
|
|
|
+
|
|
|
+ 要素
|
|
|
+
|
|
|
+* 元数据:BeanDefinition
|
|
|
+* 注册:BeanDefinitionRegistry#registerBeanDefinition
|
|
|
+* 类型:延迟和非延迟
|
|
|
+* 顺序:Bean 生命周期顺序按照注册顺序
|
|
|
+
|
|
|
+## 5、外部化配置作为依赖来源
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# 面试题
|
|
|
+
|
|
|
+1、注入和查找的来源是否相同?
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+2、单例对象能在IOC容器启动后注册码?
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+3、spring依赖注入的来源有哪些?
|
|
|
+
|
|
|
+
|