SpringBoot自动装配+bean加载+MVC
2022-06-27 15:34:16 0 举报
SpringBoot 流程
作者其他创作
大纲/内容
剩下其他核心方法
run方法入口
createBeanInstance
当前类型为RuntimeBeanReference,所以需要到容器里面先取值
@EnableAutoConfiguration
// Eagerly cache singletons to be able to resolve circular references// even when triggered by lifecycle interfaces like BeanFactoryAware.boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&isSingletonCurrentlyInCreation(beanName));if (earlySingletonExposure) {if (logger.isTraceEnabled()) {logger.trace(\"Eagerly caching bean '\" + beanName +\"' to allow for resolving potential circular references\
Reamrk此处填充bean的部分属性是因为beanFacotry和applicationContex是两条线
obtainFreshBeanFactory
ReactiveWebServerApplicationContext
resolveValueIfNecessary
最终解析方法parseBeanDefinitions
// Instantiate all remaining (non-lazy-init) singletons.beanFactory.preInstantiateSingletons();
核心读取方法doLoadBeanDefinitions
instantiateBean
赋值操作【判断值类型是否为 RuntimeBeanReference】resolvedName = String.valueOf(doEvaluate(ref.getBeanName()));bean = this.beanFactory.getBean(resolvedName);
循环依赖相关
@Import(AutoConfigurationImportSelector.class)
applyPropertyValues
getBean--> doGetBean
ServletWebServerApplicationContext
resolveReference
AbstractApplicationContext
BeanClassLoaderAware
最终解析完成后统一放入BeanDefinition
二级缓存 earlySingletonObjects
设置Bean工厂的属性值prepareBeanFactory
构造器 new SpringApplication(primarySources)
取lambda表达式获取半成品对象存入二级缓存,并且移除三级缓存
未完待续
读取XML文件流InputStream inputStream = encodedResource.getResource().getInputStream()
run
@SpringBootApplication
AnnotationConfigWebApplicationContext
spring自动装配入口
loadSpringFactories
GroovyWebApplicationContext
refresh
进行实例化方法 preInstantiateSingletons
三级缓存 缓存添加lambda表达式 二级缓存移除bean singletonFactories
BeanFactoryAware
BeanNameAware
createBean--> doCreateBean
finishBeanFactoryInitialization
@AutoConfigurationPackage
初始化bean(填充spring其他基本beanspan style=\"font-size: inherit;\
XML加载AbstractXmlApplicationContext
META-INF/spring.factories
一级缓存singletonObjects
创建对象ctor.newInstance(argsWithDefaultValues);
加载系统bean 自动装配 this.bootstrapRegistryInitializers = new ArrayList<>(getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
@Import(AutoConfigurationPackages.Registrar.class)
XmlWebApplicationContext
getSpringFactoriesInstances
获取构造器 constructorToUse = clazz.getDeclaredConstructor();
refreshContext
0 条评论
下一页