NOTE
2.32 Autowired Principle
Class inheritance diagram and principle analysis of Spring's AutowiredAnnotationBeanPostProcessor.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Class Inheritance Diagram

2. Principle Analysis
- When the Spring container refreshes, there are two key steps:
registerBeanPostProcessorsandfinishBeanFactoryInitialization. registerBeanPostProcessorsinjects theAutowiredAnnotationBeanPostProcessorBeanPostProcessor into the Spring container. It has two key methods:
postProcessMergedBeanDefinition(fromMergedBeanDefinitionPostProcessor)
The purpose of this method is to encapsulate information about fields that need dependency injection into the InjectionMetadata class. InjectionMetadata contains which elements need to be injected and into which target class those elements should be injected.
postProcessPropertyValues(fromInstantiationAwareBeanPostProcessor)
The purpose of this method is to complete dependency-property injection.
- After
finishBeanFactoryInitializationcreates the Bean instance, it callsAutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition. Then, when assigning values to properties, it callsAutowiredAnnotationBeanPostProcessor.postProcessPropertyValues. Finally, it obtains the Bean instance to inject throughBeanFactory.getBean(beanName, beanClass)and completes property injection through reflection.

Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub