Spring IOC automatic injection process

Spring annotation mode is automatically injected through AutowiredAnnotationBeanPostProcessor, CommonAnnotationBeanPostProcessor handled.

1. AutowiredAnnotationBeanPostProcessor to support automatic injection annotations: @ Autowired, @ Value, @ Inject ( if any)
injected bean will be added to RootBeanDefinition # externallyManagedConfigMembers property

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessMergedBeanDefinition

public  void postProcessMergedBeanDefinition (RootBeanDefinition BeanDefinition, Class <?> BeanType, the beanName String) { 
    InjectionMetadata Metadata = findAutowiringMetadata (the beanName, BeanType, null ); // find @ Autowired by reflection, @ Value, @ Inject injection metadata 
    metadata.checkConfigMembers (beanDefinition ); // injecting metadata information saved to the property RootBeanDefinition # externallyManagedConfigMembers 
}

 

2. CommonAnnotationBeanPostProcessor commonly used to implement support for annotation, mainly javax.annotation package JSR-250 annotations support, comprising: @Resource, @PostConstruct, @PreDestroy, JNDI, EJB, etc.

 

The final injection was performed when filling properties populateBean () a.

1. populateBean()
    1.1 AutowiredAnnotationBeanPostProcessor.postProcessProperties
        1.1.1 org.springframework.beans.factory.annotation.InjectionMetadata.inject
            1.1.1.1 AutowiredFieldElement.inject
            1.1.1.2 AutowiredMethodElement.inject
    1.2 CommonAnnotationBeanPostProcessor.postProcessProperties
        1.2.1 org.springframework.beans.factory.annotation.InjectionMetadata.inject
            1.2.1.1 ResourceElement.inject

 

 

Guess you like

Origin www.cnblogs.com/kevin-yuan/p/12126507.html