zoukankan      html  css  js  c++  java
  • SpringApplication初始化

    SpringApplication:
    private void initialize(Object[] sources) {
    if (sources != null && sources.length > 0) {
    this.sources.addAll(Arrays.asList(sources));
    }
    this.webEnvironment = deduceWebEnvironment();
    // 从spring.factories里读取所有 ApplicationContextInitializer,并记入 SpringApplication
    setInitializers((Collection) getSpringFactoriesInstances(
    ApplicationContextInitializer.class));
    // 从spring.factories里读取所有 ApplicationListener,并记入 SpringApplication
    setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    this.mainApplicationClass = deduceMainApplicationClass();
    }
    public ConfigurableApplicationContext run(String... args) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ConfigurableApplicationContext context = null;
    FailureAnalyzers analyzers = null;
    configureHeadlessProperty();
    // 从spring.factories里读取所有 SpringApplicationRunListener,监听springboot启动,参考:org.springframework.boot.context.event.EventPublishingRunListener
    SpringApplicationRunListeners listeners = getRunListeners(args);
    listeners.starting();
    try {
    ApplicationArguments applicationArguments = new DefaultApplicationArguments(
    args);
    ConfigurableEnvironment environment = prepareEnvironment(listeners,
    applicationArguments);
    Banner printedBanner = printBanner(environment);
    // web环境下默认的 ApplicationContext: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
    // 非web环境下默认的 ApplicationContext: org.springframework.context.annotation.AnnotationConfigApplicationContext
    context = createApplicationContext();
    analyzers = new FailureAnalyzers(context);
    // org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties 会通过 ApplicationContextInitializer,准备 PropertySource
    // PropertySourceBootstrapProperties 收集 PropertySourceLocator 来获得PropertySource
    // 其中 org.springframework.cloud.config.client.ConfigServicePropertySourceLocator 是 Cloud Config Client 提供的 PropertySourceLocator
    prepareContext(context, environment, listeners, applicationArguments,
    printedBanner);
    // 调用 context.refresh
    refreshContext(context);
    afterRefresh(context, applicationArguments);
    listeners.finished(context, null);
    stopWatch.stop();
    if (this.logStartupInfo) {
    new StartupInfoLogger(this.mainApplicationClass)
    .logStarted(getApplicationLog(), stopWatch);
    }
    return context;
    }
    catch (Throwable ex) {
    handleRunFailure(context, listeners, analyzers, ex);
    throw new IllegalStateException(ex);
    }
    }
  • 相关阅读:
    Object.assign () 和深拷贝
    在关机或重启前,关闭有道云笔记
    OpenSSL生成加密证书.cer和.pfx
    scrcpy 安卓投屏
    C#.NET AES CBC 加密
    华擎B365M ITX ,SSD WIN7 电脑卡顿,4K异常,9代 I7
    华擎B365 BIOS 设置来电启动,来电自启,来电后开机
    打开 gpedit.msc 组策略时弹出错误提示,"找不到资源 string.Advanced_EnableSSL3Fallback ”。
    将手机声音通过蓝牙输入到WIN10电脑
    CSS选择器——cssSelector定位方式详解
  • 原文地址:https://www.cnblogs.com/xmanblue/p/9026327.html
Copyright © 2011-2022 走看看