In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the startup process of Spring Boot and Spring Cloud applications?". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
SpringBoot application startup process
When we call the run method of SpringApplication in the Spring Boot project to start the application, the Spring Boot application startup process can be divided into three steps.
Step 1: prepare the environment Environment. An ApplicationEnvironmentPreparedEvent event (application environment preparation event) is sent, and the event is consumed synchronously. When the event listeners are called, Spring Boot continues to prepare the environment Environment, loading the application.yaml and all ActiveProfiles corresponding application- [activeProfile] .yaml configuration files.
Step 2: prepare the ApplicationContext container. The EnableAutoConfiguration that we configured in the spring.factories file is read at this time, and the class is loaded according to the configured class name, and the BeanDefinition for the class is generated and registered in the bean factory.
Step 3: refresh the ApplicationContext when everything is ready.
The Spring Boot startup process is shown in the following figure.
Spring Cloud application startup process
The Spring Cloud project can configure a BootstrapConfiguration class in the spring.factories configuration file, which is no different from the EnableAutoConfiguration class provided by Spring Boot, except that they act in different ApplicationContext containers.
When Spring Cloud dependencies are added to the project, the run method of SpringApplication starts two containers, two ApplicationContext. The original application startup process has also changed.
Spring Cloud's BootstrapApplicationListener listens for ApplicationEnvironmentPreparedEvent events and opens a new ApplicationContext container when listening for events. We can call this ApplicationContext container Spring Cloud's Bootstrap container.
The Bootstrap container is used to register all BootstrapConfiguration configured in the spring.factories configuration file and to use its Bean factory as the parent factory of the ApplicationContext container's Bean factory that was originally started by Spring Boot after the Bootstrap container is initialized, as shown in the following figure.
This Bootstrap container for the Spring Cloud layer seems to be tailored by Spring Cloud specifically for dynamic configuration.
The startup process for Spring Cloud is shown in the following figure.
When Spring Cloud is created to launch a Bootstrap container for an application, it also goes through the startup process of the Spring Boot application. On the other hand, calling the run method of SpringApplication in the original main method to start the ApplicationContext container will get stuck in the environment preparation phase, waiting for Spring Cloud to provide it with a parent factory.
The bootstrap. [Yaml | props] configuration file is ready to read and write to the Environment of the Bootstrap container before starting the Bootstrap container when BootstrapApplicationListener listens for the Environment event.
BootstrapApplicationListener identifies whether the current container is a Bootstrap container by judging whether bootstrap exists in the Bootstrap, so as to solve the problem of infinitely listening to ApplicationEnvironmentPreparedEvent events to start a new container.
This is the end of the content of "what is the startup process of Spring Boot and Spring Cloud applications". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.