diff --git a/.gitattributes b/.gitattributes
index 2ab2d3c..2255dfe 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,3 +2,4 @@
*.js linguist-language=java
*.css linguist-language=java
*.html linguist-language=java
+
diff --git a/.gitignore b/.gitignore
index 853f53d..dfe0d14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ dataSources/
### OS ###
.DS_Store
+
diff --git a/README.md b/README.md
index d82a3dc..7d92f9a 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,6 @@
-> - 2022-01-21紧急:由于我所使用的图床暂时出了点问题,图片访问可能会有问题【没问题的话可以忽略这条消息】。批量替换比较麻烦,我想暂时等几天看看,官方没有恢复的话,我准备转移图床。如果有读者很急的话,可以访问图片源文件,我将所有的图片存到了网盘,将文章和图片下到本地然后放到对应的markdown文件夹下面,然后批量替换路径即可。
->
-> 阿里网盘:https://www.aliyundrive.com/s/43jcQbstUpX
->
-> 百度网盘:https://pan.baidu.com/s/1fb-Rt7Hq7C8Zo82jLANnuQ 提取码:u4sf
->
+
> 1. 文章会优先发布在[Github](https://github.com/youthlql/JavaYouth),其它平台会晚一段时间,文章纠错与更新内容只在Github。如果Github很卡,可以在去[Gitee](https://gitee.com/youthlql/JavaYouth)克隆。
> 2. 提供两种在线阅读方式:[电子书在线阅读](https://imlql.cn/JavaYouth/#/),[个人博客](https://imlql.cn/)浏览。
@@ -143,7 +138,7 @@
-## 源码【01.01更新】
+## 源码【01.27更新】
@@ -153,6 +148,10 @@
[03.第3章-后置处理器和Bean生命周期](docs/spring-sourcecode-v1/03.第3章-后置处理器和Bean生命周期.md)
+[04.第4章-Bean初始化流程](docs/spring-sourcecode-v1/04.第4章-Bean初始化流程.md)
+
+
+
# Netty
## 入门
diff --git a/docs/spring-sourcecode-v1/04.第4章-Bean初始化流程.md b/docs/spring-sourcecode-v1/04.第4章-Bean初始化流程.md
new file mode 100644
index 0000000..7500040
--- /dev/null
+++ b/docs/spring-sourcecode-v1/04.第4章-Bean初始化流程.md
@@ -0,0 +1,1338 @@
+---
+title: Spring源码系列-第4章-Bean初始化流程
+tags:
+ - Spring源码
+categories:
+ - Spring
+ - 源码V1
+keywords: Spring,框架,spring源码
+description: 总结一下Bean的初始化
+cover: 'https://gitee.com/youthlql/randombg/raw/master/logo/spring.png'
+abbrlink: 49f419ae
+date: 2022-01-27 21:01:02
+---
+
+# 第4章-Bean初始化流程
+
+## 流程图-bean初始化流程
+
+
+
+## AbstractApplicationContext#refresh()
+
+```java
+ @Override //容器刷新的十二大步。模板模式
+ public void refresh() throws BeansException, IllegalStateException {
+ synchronized (this.startupShutdownMonitor) {
+ StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
+
+ // Prepare this context for refreshing.
+ prepareRefresh();
+
+ // Tell the subclass to refresh the internal bean factory.
+ // 工厂创建:BeanFactory第一次开始创建的时候,有xml解析逻辑。
+ ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
+
+ // Prepare the bean factory for use in this context.
+ prepareBeanFactory(beanFactory);
+
+ try {
+ // Allows post-processing of the bean factory in context subclasses.
+ postProcessBeanFactory(beanFactory);
+
+ StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
+ //工厂增强:执行所有的BeanFactory后置增强器;利用BeanFactory后置增强器对工厂进行修改或者增强,配置类会在这里进行解析。 Invoke factory processors registered as beans in the context.
+ invokeBeanFactoryPostProcessors(beanFactory);
+
+ //注册所有的Bean的后置处理器 Register bean processors that intercept bean creation.
+ registerBeanPostProcessors(beanFactory);
+ beanPostProcess.end();
+
+ // Initialize message source for this context.
+ initMessageSource();
+
+ // Initialize event multicaster for this context.
+ initApplicationEventMulticaster();
+
+ // Initialize other special beans in specific context subclasses.
+ onRefresh();
+
+ //注册监听器,从容器中获取所有的ApplicationListener; Check for listener beans and register them.
+ registerListeners();
+
+ // Instantiate all remaining (non-lazy-init) singletons.
+ //bean创建;完成 BeanFactory 初始化。(工厂里面所有的组件都好了)
+ finishBeanFactoryInitialization(beanFactory);
+
+ // Last step: publish corresponding event.
+ finishRefresh();
+ }
+
+ catch (BeansException ex) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Exception encountered during context initialization - " +
+ "cancelling refresh attempt: " + ex);
+ }
+
+ // Destroy already created singletons to avoid dangling resources.
+ destroyBeans();
+
+ // Reset 'active' flag.
+ cancelRefresh(ex);
+
+ // Propagate exception to caller.
+ throw ex;
+ }
+
+ finally {
+ // Reset common introspection caches in Spring's core, since we
+ // might not ever need metadata for singleton beans anymore...
+ resetCommonCaches();
+ contextRefresh.end();
+ }
+ }
+ }
+
+
+```
+
+## AbstractApplicationContext#finishBeanFactoryInitialization()
+
+```java
+ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
+ // 给工厂设置好 ConversionService【负责类型转换的组件服务】, Initialize conversion service for this context.
+ if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) &&
+ beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
+ beanFactory.setConversionService(
+ beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
+ }
+
+ // 注册一个默认的值解析器("${}") ;Register a default embedded value resolver if no BeanFactoryPostProcessor
+ // (such as a PropertySourcesPlaceholderConfigurer bean) registered any before:
+ // at this point, primarily for resolution in annotation attribute values.
+ if (!beanFactory.hasEmbeddedValueResolver()) {
+ beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
+ }
+
+ // LoadTimeWeaverAware;aspectj:加载时织入功能【aop】。 Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
+ String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
+ for (String weaverAwareName : weaverAwareNames) {
+ getBean(weaverAwareName); //从容器中获取组件,有则直接获取,没则进行创建
+ }
+
+ // Stop using the temporary ClassLoader for type matching.
+ beanFactory.setTempClassLoader(null);
+
+ // Allow for caching all bean definition metadata, not expecting further changes.
+ beanFactory.freezeConfiguration();
+
+ // Instantiate all remaining (non-lazy-init) singletons.
+ //初始化所有的非懒加载的单实例Bean
+ beanFactory.preInstantiateSingletons();
+ }
+```
+
+
+
+
+
+## DefaultListableBeanFactory#preInstantiateSingletons()
+
+```java
+
+ String FACTORY_BEAN_PREFIX = "&";
+
+ public void preInstantiateSingletons() throws BeansException {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Pre-instantiating singletons in " + this);
+ }
+
+ // Iterate over a copy to allow for init methods which in turn register new bean definitions.
+ // While this may not be part of the regular factory bootstrap, it does otherwise work fine.
+ List beanNames = new ArrayList<>(this.beanDefinitionNames);
+
+ // 创建出所有的单实例Bean;Trigger initialization of all non-lazy singleton beans...
+ for (String beanName : beanNames) {
+ RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName); //开始解析文件的时候每一个bean标签被解析封装成一个BeanDefinition
+ if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
+ if (isFactoryBean(beanName)) { //如果是FactoryBean则执行下面逻辑
+ Object bean = getBean(FACTORY_BEAN_PREFIX + beanName); //得到HelloFactory
+ if (bean instanceof FactoryBean) {
+ FactoryBean> factory = (FactoryBean>) bean;
+ boolean isEagerInit;
+ if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
+ isEagerInit = AccessController.doPrivileged(
+ (PrivilegedAction) ((SmartFactoryBean>) factory)::isEagerInit,
+ getAccessControlContext());
+ }
+ else {
+ isEagerInit = (factory instanceof SmartFactoryBean &&
+ ((SmartFactoryBean>) factory).isEagerInit());
+ }
+ if (isEagerInit) {
+ getBean(beanName);
+ }
+ }
+ }
+ else { //不是FactoryBean则执行这个,普通的单实例非懒加载bean的创建
+ getBean(beanName); //
+ }
+ }
+ }
+
+ // 触发 post-initialization 逻辑; Trigger post-initialization callback for all applicable beans...
+ for (String beanName : beanNames) {
+ Object singletonInstance = getSingleton(beanName);
+ if (singletonInstance instanceof SmartInitializingSingleton) {
+ StartupStep smartInitialize = this.getApplicationStartup().start("spring.beans.smart-initialize")
+ .tag("beanName", beanName);
+ SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton) singletonInstance;
+ if (System.getSecurityManager() != null) {
+ AccessController.doPrivileged((PrivilegedAction