Spring原始碼之事務(一)— TransactionAutoConfiguration自動配置
阿新 • • 發佈:2020-11-19
#### 總結:
- 在ConfigurationClassParser#parse()中會對deferredImportSelectorHandler進行處理(在處理@ComponentScan 自己所寫@Component的類後)
- 處理過程中會呼叫SpringFactoriesLoader#loadFactoryNames(),去查詢所有jar下面META-INF/spring.factories中key為org.springframework.boot.autoconfigure.EnableAutoConfiguration的值
- ConfigurationClassPostProcessor#processConfigBeanDefinitions()中loadBeanDefinitions對TransactionAutoConfiguration進行BeanDefinition的載入,並註冊IOC容器
#### TransactionAutoConfiguration的BeanDefinition載入解析
呼叫鏈:
> AbstractApplicationContext#refresh() --> AbstractApplicationContext#invokeBeanFactoryPostProcessors() --> PostProcessorRegistrationDelegate#invokeBeanFactoryPostProcessors() --> PostProcessorRegistrationDelegate#invokeBeanDefinitionRegistryPostProcessors() --> ConfigurationClassPostProcessor#postProcessBeanDefinitionRegistry()--> ConfigurationClassPostProcessor#processConfigBeanDefinitions() --> ConfigurationClassPostProcessor#parse() --> ConfigurationClassParser#process() --> ConfigurationClassParser$DeferredImportSelectorGroupingHandler#processGroupImports() --> ConfigurationClassParser#processImports() --> ConfigurationClassParser#processConfigurationClass() --> ConfigurationClassParser#doProcessConfigurationClass()
ConfigurationClassParser#parse() 對延遲ImportSelector進行處理
```
private final DeferredImportSelectorHandler deferredImportSelectorHandler = new DeferredImportSelectorHandler();
public void p