spring启动加载bean日志
1 | 2017-04-14 10:01:05,511 - org.springframework.core.env.StandardEnvironment -0 [main] DEBUG - Initializing new StandardEnvironment |
1)创建bean是先检查缓存是否有或利用this.singletonsCurrentlyInCreation.containsKey(beanName)条件过滤正在创建中的bean(singletonObject = this.earlySingletonObjects.get(beanName);),没有就创建bean
1 | DefaultSingletonBeanRegistry: 180行 |
2)创建bean时先标明这个bean正在创建singletonsCurrentlyInCreation.put(beanName, Boolean.TRUE), getEarlyBeanReference()
1 | DefaultSingletonBeanRegistry: 217行 标记bean正在创建 |
1 | /** |
3) 利用缓存bean。检测改bean是否是正在创建的bean,然后利用getObjectForBeanInstance
()方法获取真正bean