Spring source code parsing (two) - Spring Bean created

Get Bean Spring container and create Bean will call getBean () method

the getBean () -> doGetBean ()
1.transformedBeanName (name); obtaining the beanName, there may be an alias (aliasMap)
2.getSingleton (the beanName); acquired from the cache (singletonObjects), if present is returned
3. Get parent container container, and if the presence of the parent container does not exist currently defined Bean current container, it tries to obtain from the parent vessel
4.getMergedLocalBeanDefinition (beanName); Get Bean Bean definitions and to verify whether the abstract class
5. obtain dependent from the Bean the Bean (dependsOn), if present, is to create dependency Bean, to create a way that the current process getBean ()
6. create a singletion, call getSingleton () -> createBean () , will change the value of a variety of containers before and after creation , to prevent conflict or recreating the case
7. Create the prototype, createBean call (), modifies the value of a variety of containers before or after creating, recreating or prevent conflict situation
8. Create another scope (request, session). Will get when you create the request or the session, get less calls createBean (), it will change the value of a variety of containers before and after creation, created to prevent duplication or conflict situations

createBean ()
1.resolveBeanClass (MBD, the beanName); Bean type of acquired
2. calls the postprocessor InstantiationAwareBeanPostProcessor postProcessBeforeInstantiation (beanClass, beanName) method
  if the return object post-processor, the post-processor InstantiationAwareBeanPostProcessor call postProcessAfterInstantiation ( beanClass, beanName) method returns the object and
  the post-processor is the role before the object is created, the opportunity to create a proxy to achieve AOP is used in this manner.
3. The method of creating a real call doCreateBean (the beanName, mbdToUse, args);
4. the call postprocessor SmartInstantiationAwareBeanPostProcessor determineCandidateConstructors (beanClass, beanName) method for obtaining the constructor
5. If the acquired constructor is configured with the current creates an object, if the acquisition is less than the no-argument constructor to use to create instantiateBean (beanName, mbd), this Bean has been created but not initialized
6. call postprocessor MergedBeanDefinitionPostProcessor of postProcessMergedBeanDefinition (mbd, beanType, beanName) method
7. populateBean (beanName, mbd, instanceWrapper) ; filled Bean, setting properties
  7.1 postprocessor InstantiationAwareBeanPostProcessor the call postProcessAfterInstantiation (beanClass, beanName) method
  7.2 postprocessor InstantiationAwareBeanPostProcessor the call postProcessPropertyValues () method returns the PropertyValues
  7.3 applyPropertyValues (the beanName, MBD, BW, PVS); attribute value is returned to the application
8.initializeBean (beanName, exposedObject, mbd); initialization Bean
  7.1 interface method calls Aware invokeAwareMethods (). BeanNameAware, BeanClassLoaderAware, the BeanFactoryAware
  7.2 calls the postprocessor BeanPostProcessor of postProcessBeforeInitialization () method of
  7.3 to perform the initialization method invokeInitMethods (). InitializingBean.afterPropertiesSet (), @ Bean annotated method initMethod attribute specifies
  postProcessAfterInitialization 7.4 calls the post-processor BeanPostProcessor () methods
  7.5 to determine whether there are ways Bean attribute specifies the method of destruction, @ Bean annotation destoryMethod. If the method of packaging as DisposableBeanAdapter and poured into the container, when the container is closed to call

 

"Spring Source resolved (a) - Spring container Refresh"

《Spring源码解析(二)--Spring Bean创建》

Guess you like

Origin www.cnblogs.com/zhuqianchang/p/11418189.html