NOTE
2.32 Autowired Principle
Spring handles dependency injection during post-processor registration and bean creation. These notes trace @Autowired through AutowiredAnnotationBeanPostProcessor.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Class Inheritance Diagram

2. Implementation 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 records the elements to inject and their target classes.
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.

3. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub