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 @   王广元  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
分享到:
点击右上角即可分享
微信分享提示