spring boot process to prepare the environment

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/yj1499945/article/details/87087541
    private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
        context.setEnvironment(environment);
        this.postProcessApplicationContext(context);
        this.applyInitializers(context);
        listeners.contextPrepared(context);
        if (this.logStartupInfo) {
            this.logStartupInfo(context.getParent() == null);
            this.logStartupProfileInfo(context);
        }

        context.getBeanFactory().registerSingleton("springApplicationArguments", applicationArguments);
        if (printedBanner != null) {
            context.getBeanFactory().registerSingleton("springBootBanner", printedBanner);
        }

        Set<Object> sources = this.getSources();
        Assert.notEmpty(sources, "Sources must not be empty");
        this.load(context, sources.toArray(new Object[sources.size()]));
        listeners.contextLoaded(context);
    }

setEnvironment context to initialize the environment

postProcessApplicationContext context and setting ResourceLoader ClassLoader

applyInitializers some contexts initializers class files from spring.factories

# Application Context Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer
  • DelegatingApplicationContextInitializer: ApplicationContext initializer delegate processing, which requires an initialization process from the delegate property context.initializer.classes Spring environment, the attribute may be separated by commas plurality initializer.
  • ContextIdApplicationContextInitializer: set the id to ApplicationContext. Set in accordance with the following order of arrangement, spring.application.name, vcap.application.name, spring.config.name, if these are not arranged in environment configuration, use "application" to represent the default profiles will also be further added to the id go.
  • ConfigurationWarningsApplicationContextInitializer: output warning log information.
  • ServerPortInfoApplicationContextInitializer: add a EmbeddedServletContainerInitializedEvent event listener, set the trigger to start the embedded WEB service port. . [Namespace] .port sets the start through the port attribute local, which is ApplicationContext specified namespace namespace namespace if empty, is used to indicate attributes local.server.port port configuration.

 

contextPrepared distribute events to other listeners

This method is mainly load the startup class registered into the container.

 

 

Guess you like

Origin blog.csdn.net/yj1499945/article/details/87087541