spring bean source depth analysis of dependency injection DI in the end how to do - that is, analysis AutowiredAnnotationBeanPost and CommonAnnotationBeanPostProcessor (b)

Previous Cipian combined, where separate analysis @autowired @resouce supported by field notes and methods of implantation process in the end how, that comment from them is appropriate resolution, appropriate start dependency injection analysis

(Because of the particularity @resouce notes, it is recommended to look at my previous blog post, analyzed the information field corresponding to the field he was @resouce use will be placed in a cache maintained in CommonAnnotationBeanPostProcessor, here I am 猜测到it's similar analysis found @Autowired 注解的解析certainly put on AutowiredAnnotationBeanPosta cache attribute map which is defined above, and it should be instantiated in the target bean, i.e. the former property 【apply_Merged_BeanDefinitionPostProcessors】calls to the combined use of a post-processor interface method AutowiredAnnotationBeanPosthis postProcessMergedBeanDefinitionlogical completion of annotation (methods, fields ) analytical cached on map inside its parent class and, specifically used in the following)
Here Insert Picture Description

First of all, let me comb it again the way many cases of dependency injection (both with annotation ha)

  1. I need to angle except Kazakhstan constructor injection, 构造器注入我举得非常特殊because it is not the property of the pupulate stage, and there are ways of parametric structure above 是不需要加@Autowired 注解的, many people are added to the above, in fact, does not make sense, so why should I say, ->
    (1 in by constructor injection instantiate target bean process which is useful to start to finish did not see annotations @Autowired, it can not be used because of the thing,
    2. because @autowired annotations are instantiated in the target bean, It began to be completed before the property is set pupulateBean resolves to!)

Dependent stage injection occurs 2.pupulate

After this constructor not by way of injection, i.e., no parameters are configured to achieve a target bean instance, property injection stage is completed parsing the attributes of the target bean.

And can be divided into two categories according to, are or need to add annotations @Autowired @resouce,
Class 1: Direct annotations placed above the field - so-called field implantation
Class 2: Direct annotation into the above method - also called the method --setter injection

Published 43 original articles · won praise 14 · views 3565

Guess you like

Origin blog.csdn.net/qq_39965727/article/details/104680012