源码地址:https://github.com/spring-projects/spring-framework
仓库地址:https://gitcode.net/qq_42665745/spring/-/tree/14-auto-property
@Autowired、@Value、@Component
注解注入属性的实现分散在refresh容器的各个方法中,梳理:
- refreshBeanFactory中扫描带@Component的类,并将其解析成BeanDefinition注册到容器中,最后还要注册AutowiredAnnotationBeanPostProcessor的定义到容器中
- invokeBeanFactoryPostProcessors中会对BeanDefinition的${}进行替换,然后向容器中添加字符串解析器PlaceholderResolvingStringValueResolver,供解析@Value注解使用
- registerBeanPostProcessors中初始化并注册AutowiredAnnotationBeanPostProcessor到容器中
- preInstantiateSingletons中创建Bean对象时,实例化Bean后,属性注入前,进行@Value、@Autowired、@Qulifier的解析