SpringBoot-2.7.8---工作流程:
Sb30StartupApplication【10】->SpringApplication.run(Sb30StartupApplication.class, args);
SpringApplication【815】->return run(new Class[]{primarySource}, args);
SpringApplication【819】->return (new SpringApplication(primarySources)).run(args);
#加载各种配置信息,初始化各种配置对象
SpringApplication【819】->new SpringApplication(primarySources))
SpringApplication【98】->this((ResourceLoader)null, primarySources);
SpringApplication【101】->public SpringApplication(ResourceLoader resourceLoader, Class... primarySources) {
SpringApplication【102】->this.sources = new LinkedHashSet();
SpringApplication【103】->this.bannerMode = Mode.CONSOLE;
SpringApplication【104】->this.logStartupInfo = true;
SpringApplication【105】->this.addCommandLineProperties = true;
SpringApplication【106】->this.addConversionService = true;
SpringApplication【107】->this.headless = true;
SpringApplication【108】->this.registerShutdownHook = true;
SpringApplication【109】->this.additionalProfiles = Collections.emptySet();
SpringApplication【110】->this.isCustomEnvironment = false;
SpringApplication【111】->this.lazyInitialization = false;
SpringApplication【112】->this.applicationContextFactory = ApplicationContextFactory.DEFAULT;
SpringApplication【113】->this.applicationStartup = ApplicationStartup.DEFAULT;
#初始化资源加载器
SpringApplication【114】->this.resourceLoader = resourceLoader;
SpringApplication【115】->Assert.notNull(primarySources, "PrimarySources must not be null");
# 初始化配置类的类名信息(样式转换)
SpringApplication【116】->this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
#确认当前容器加载的类型
SpringApplication【117】->this.webApplicationType = WebApplicationType.deduceFromClasspath();
#获取系统配置引导信息
SpringApplication【118】->this.bootstrapRegistryInitializers = new ArrayList(this.getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
#获取BootstrapRegistryInitializer.class对应的实例
SpringApplication【119】->this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
#初始化监听器 对初始化过程及运行过程进行干预
SpringApplication【120】->this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
#初始化引导类的类名信息
SpringApplication【121】->this.mainApplicationClass = this.deduceMainApplicationClass();
#初始化容器
SpringApplication【819】->new SpringApplication(primarySources)).run(args);
SpringApplication【143】->public ConfigurableApplicationContext run(String... args) {
#计时器开始
SpringApplication【144】->long startTime = System.nanoTime();
#系统引导信息对应的上下文对象
SpringApplication【145】->DefaultBootstrapContext bootstrapContext = this.createBootstrapContext();
SpringApplication【146】->ConfigurableApplicationContext context = null;
#模拟输入输出信号,避免因缺少外设而导致的信号传输失败(模拟显示器,键盘,鼠标,)
SpringApplication【147】->this.configureHeadlessProperty();
#获取当前注册的所有监听器
SpringApplication【148】->SpringApplicationRunListeners listeners = this.getRunListeners(args);
#监听器执行了对应的操作步骤
SpringApplication【149】->listeners.starting(bootstrapContext, this.mainApplicationClass);
#获取参数值
SpringApplication【152】-> ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
#将前期读取的数据加载成一个环境对象,用来描述信息
SpringApplication【153】-> ConfigurableEnvironment environment = this.prepareEnvironment(listeners, bootstrapContext, applicationArguments);
#做一个配置,备用
SpringApplication【154】-> this.configureIgnoreBeanInfo(environment);
#打印图标
SpringApplication【155】-> Banner printedBanner = this.printBanner(environment);
#创建容器对象,根据前期配置的容器类型判定并创建
SpringApplication【156】-> context = this.createApplicationContext();
#设置启动模式
SpringApplication【157】-> context.setApplicationStartup(this.applicationStartup);
#对容器进行设置,参数来源于前期的设定
SpringApplication【158】-> this.prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
#刷新容器环境
SpringApplication【159】-> this.refreshContext(context);
#刷新容器环境后做的后处理
SpringApplication【160】-> this.afterRefresh(context, applicationArguments);
#计时器结束
SpringApplication【161】-> Duration timeTakenToStartup = Duration.ofNanos(System.nanoTime() - startTime);
#判断是否记录启动时间的日志
SpringApplication【162】-> if (this.logStartupInfo) {
#创建日志对应的对象,输出日志信息,包含启动时间
SpringApplication【163】-> (new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), timeTakenToStartup);
#监听器执行了对应的操作步骤
SpringApplication【166】-> listeners.started(context, timeTakenToStartup);
SpringApplication【167】-> this.callRunners(context, applicationArguments);
#计时器结束
SpringApplication【174】-> Duration timeTakenToReady = Duration.ofNanos(System.nanoTime() - startTime);
#监听器执行了对应的操作步骤
SpringApplication【175】-> listeners.ready(context, timeTakenToReady);
SpringApplication【176】-> return context;