侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

源码分析

Dettan
2021-04-10 / 0 评论 / 0 点赞 / 167 阅读 / 1,289 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

启动流程
1.
如果我们使用的是SpringApplication的静态run方法,首先需要创建一个SpringApplication对象实例。
a)使用SpringFactoriesLoader在应用的classpath中查找并加载所有可用的ApplicationContextInitialize
b)使用SpringFactoriesLoader在应用的classpath中查找并加载所有可用的ApplicationListener
c)设置main方法的定义类
2.
开始执行run方法的逻辑,首先遍历执行所有通过SpringFactoriesLoader加载到的SpringApplicationRunListener,调用它们的started()方法,告诉这些SpringApplicationRunListener,SpringBoot应用要开始执行了。
3.
创建并配置当前SpringBoot应用将要使用的Environment
4.
遍历并调用所有的SpringApplicationRunListener的environmentPrepared()方法,告诉它们,Springboot应用使用的Environment准备好了
5.
确定SpringBoot应用创建什么类型的ApplicationContext,并创建完成,然后根据条件决定是否使用自定义的ShutdownHook,是否使用自定义的BeanNameGenerator,是否使用自定义的ResourceLoader,然后将准备好的Environment设置给创建好的ApplicationContext使用
6.
ApplicationContext创建完成,SpringApplication调用之前加载的ApplicationContextInitialize的initialize方法对创建好的ApplicationContext进行进一步的处理
7.
遍历所有SpringApplicationRunListener的contextPrepared()方法,通知它们,SpringBoot应用使用的ApplicationContext准备好了
8.
将之前通过@EnableAutoConfiguration获取的所有配置以及其他形式的Ioc容器配置加载到已经你准备完毕的ApplicationContext
9.
遍历所有的SpringApplicationRunListener的contextLoader()方法,告知ApplicationContext已装载完毕
10.
调用ApplicationContext的refresh()方法,完成Ioc容器可用的最后一道工序
11.
查找当前ApplicationContext中是否注册有CommandLineRunner,如果有,则遍历执行它们
12.
遍历所有的SpringApplicationRunListener的finished()方法,告知,“初始化完成”


org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean 获取bean的
org.springframework.core.io.support.SpringFactoriesLoader#loadFactoryNames(org.springframework.context.ApplicationContextInitializer) 加载所有的过滤器,和好多东西
"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  在org.apache.shiro.realm.text.IniRealm.onInit(IniRealm.java:137)
	  在org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398)
	  在org.apache.shiro.spring.LifecycleBeanPostProcessor.postProcessBeforeInitialization(LifecycleBeanPostProcessor.java:89)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	  在org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$154.1961129028.getObject(Unknown Source:-1)
	  在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	  - 锁定 <0x18f1> (a java.util.concurrent.ConcurrentHashMap)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	  在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1508)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1472)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1361)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1210)
	  在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
	  在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
	  在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	  在org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$154.1961129028.getObject(Unknown Source:-1)
	  在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	  在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1290)
	  在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1210)
	  在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
	  在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
	  在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	  在org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$154.1961129028.getObject(Unknown Source:-1)
	  在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
	  在org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:91)
	  在org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:109)
	  在org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:92)
	  在org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:101)
	  在org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:251)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1141)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1114)
	  在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:506)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	  在org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$154.1961129028.getObject(Unknown Source:-1)
	  在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	  在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
	  在org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:240)
	  在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:722)
	  在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)
	  - 锁定 <0x195b> (a java.lang.Object)
	  在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	  在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	  在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	  在org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	  在org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	  在org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	  在com.learn.EstateApplication.main(EstateApplication.java:36)

0

评论区