SpringBoot学习笔记-SpringApplication.run分析

SpringApplication

这个类主要做了一下四件事情

  • 推断应用的类型是普通的项目还是Web项目
  • 查找并加载所有可用初始化器,设置到initializers属性中
  • 找出所有的应用程序监听器,设置到listeners属性中
  • 推断并设置main的定义类,找到运行的主体

查看构造器

    public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
        this.sources = new LinkedHashSet();
        this.bannerMode = Mode.CONSOLE;
        this.logStartupInfo = true;
        this.addCommandLineProperties = true;
        this.addConversionService = true;
        this.headless = true;
        this.registerShutdownHook = true;
        this.additionalProfiles = Collections.emptySet();
        this.isCustomEnvironment = false;
        this.lazyInitialization = false;
        this.applicationContextFactory = ApplicationContextFactory.DEFAULT;
        this.applicationStartup = ApplicationStartup.DEFAULT;
        this.resourceLoader = resourceLoader;
        Assert.notNull(primarySources, "PrimarySources must not be null");
        this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
        this.webApplicationType = WebApplicationType.deduceFromClasspath();
        this.bootstrapRegistryInitializers = new ArrayList(this.getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
        this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class)); //查找并加载所有可用初始化器,设置到initializers属性中
        this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));  //找出所有的应用程序监听器,设置到listeners属性中
        this.mainApplicationClass = this.deduceMainApplicationClass();

run方法流程分析

面试问题:谈谈对SpringBoot的理解:

  • 自动装配
  • run()
posted @ 2022-08-07 21:57  王广元  阅读(59)  评论(0)    收藏  举报
分享到: