汇总一下,就是:
支持解析的注解 beanDefinition中class的类别 beanClassConfiguration BeanFactoryPostProcessor ConfigurationClassPostProcessor
Autowired BeanPostProcessor AutowiredAnnotationBeanPostProcessor
Required BeanPostProcessor RequiredAnnotationBeanPostProcessor
PostConstruct/PreDestroy/
Resource/EJB/WebServiceRef BeanPostProcessor CommonAnnotationBeanPostProcessor
我们下面再简单地列举一下,这几个beanClass的继承结构:
AutowiredAnnotationBeanPostProcessor简单分析我们在前面的例子中,进行了以下注入:
@Controller @Data public class TestController { @Autowired private TestService testService; }大家可以想象下,这个“TestService testService字段,需要注入”,这个元数据会存储在哪?
BeanDefinition?我们看看呢:
这个图,就是我用json输出的TestController的beanDefinition,这里面并没有出现TestService的声影。
我来告诉大家,这个数据,实际是在getBean的时候,由AutowiredAnnotationBeanPostProcessor来获取的,具体的堆栈,大家可以看看:
具体的方法就是在下边的buildAutowiringMetadata:
private InjectionMetadata findAutowiringMetadata(Class<?> clazz) { // Quick check on the concurrent map first, with minimal locking. InjectionMetadata metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { synchronized (this.injectionMetadataCache) { metadata = this.injectionMetadataCache.get(clazz); if (metadata == null) { // 这里啊,去寻找要自动注入的数据 metadata = buildAutowiringMetadata(clazz); this.injectionMetadataCache.put(clazz, metadata); } } } return metadata; }