Spring IOC全网最详细时序图(非Web方式启动)---持续更新
2020-12-01 19:37:17 0 举报
Spring IOC全网最详细时序图(非Web方式启动)---持续更新
作者其他创作
大纲/内容
扫描指定包下面的带有@Component注解的类
AspectJAwareAdvisorAutoProxyCreator
registerOrEscalateApcAsRequired()
applyBeanPostProcessorsBeforeInstantiation()
invokeBeanDefinitionRegistryPostProcessors()
AbstractAdvisorAutoProxyCreator
DefaultResourceLoader
- classLoader:ClassLoader
+ DefaultResourceLoader()
1. 处理内部类上有@Component注解的情况2. 处理@PropertySource3. 处理@ComponentScan4. 处理@Import5. 处理@ImportResource6. 处理@Bean7. 处理接口的default方法8. 处理superclass
registerBeanDefinition()
1. 处理@ComponentScan的一些属性2. 调用doScan()
invokeBeanFactoryPostProcessors()
实例化并调用所有注册的BeanFactoryPostProcessor,优先BeanDefinitionRegistryPostProcessors
Invoke the given BeanDefinitionRegistryPostProcessor beans
BeanFactoryAspectJAdvisorsBuilder
postProcessBeforeInstantiation()
new DefaultListableBeanFactory();
parse()
ClassPathBeanDefinitionScanner
resolveBeforeInstantiation()
register()
BeanFactoryAdvisorRetrievalHelper
loadBeanDefinitionsForConfigurationClass()
查找事务代理
BeanDefinitionRegistryPostProcessors
postProcessBeanDefinitionRegistry()
findCandidateAdvisors()
创建classLoader:ClassUtils.getDefaultClassLoader();
ReflectiveAspectJAdvisorFactory
PostProcessorRegistrationDelegate
添加到BeanDefinitions:org.springframework.context.annotation.internalConfigurationAnnotationProcessororg.springframework.context.event.internalEventListenerFactoryorg.springframework.context.event.internalEventListenerProcessororg.springframework.context.annotation.internalAutowiredAnnotationProcessor如果支持JSR-250和JPA还有其他要添加
AnnotationConfigApplicationContext
- reader:AnnotatedBeanDefinitionReader
+ AnnotationConfigApplicationContext()
getAdvisors()
AbstractAutoProxyCreator
加载类继承BeanDefinitionRegistryPostProcessor,可以自定义类继承此类,实现拓展
postProcessBeanFactory()
registerBeanPostProcessors()
GenericApplicationContext
- beanFactory:DefaultListableBeanFactory
+ GenericApplicationContext()
implements
loadBeanDefinitionsFromRegistrars()
Ordered
1. 挑选出未处理过的BeanDefinition,按Order排序2. 检测是否有自定义的类名生成策略3. 依次处理每个@Configuration class
ConfigurationClassPostProcessor
registerBean()
事先将ConfigurationClassPostProcessor添加到Processors,然后激活,用来扫描包下的类,符合条件的添加到BeanDefinition Map
this.reader = new AnnotatedBeanDefinitionReader(this); this.scanner = new ClassPathBeanDefinitionScanner(this);
BeanDefinitionRegistryPostProcessor
+ postProcessBeanDefinitionRegistry()
ConfigurationClassBeanDefinitionReader
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);
循环调用registerBean()
createBean()
以@ComponentScan为例来分析
getBean()
findCandidateComponents()
AbstractApplicationContext
- resourcePatternResolver:ResourcePatternResolver
+ AbstractApplicationContext()
processConfigurationClass()
辅助类
AnnotationAwareAspectJAutoProxyCreator
ClassPathScanningCandidateComponentProvider
BeanFactoryPostProcessor
+ postProcessBeanFactory()
AbstractAutowireCapableBeanFactory
processImports()
doRegisterBean()
register \"org.springframework.aop.config.internalAutoProxyCreator\"
loadBeanDefinitions()
AnnotatedBeanDefinitionReader
scanCandidateComponents()
ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor所以先执行,加载指定包或类内加载的Bean
invoke registerBeanDefinitions()
doScan()
ImportBeanDefinitionRegistrar
+ registerBeanDefinitions()
AspectJAutoProxyRegistrar
refresh()
this.reader.register(componentClasses);
this()
AnnotationConfigApplicationContext
1. 判断是否解析过:aspectNames==null2. 若没有,获取容器中所有组件名称3. 循环所有beanName4. 通过beanName获取beanType5. 根据beanType判断是不是切面类6. 如果是,获取增强器getAdvisors(),获取切面类和切面名称7.
doProcessConfigurationClass()
findAdvisorBeans()
ComponentScanAnnotationParser
保存在DefaultListableBeanFactory#beanDefinitionMap(ConcurrentHashMap)
调用构造方法
登记BeanDefinition
doGetBean()
registerPostProcessor()
PriorityOrdered
shouldSkip()
@Import(AOP处理@EnableAspectJAutoProxy)
AopConfigUtils
BeanDefinitionReaderUtils
DefaultListableBeanFactory
buildAspectJAdvisors()
用来加载资源:getResourcePatternResolver();
AnnotationConfigUtils
ConfigurationClassParser
AbstractBeanFactory
0 条评论
下一页