In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Preface
Happy moment
Friends like to go, the first time to push the door is a student Meimei, feel good; then often go, sometimes a nurse, sometimes a stewardess, sometimes a teacher. It was a policewoman who pushed the door in last night. She was a good-looking thief and had a good figure. My friend jumped on it with a cry. Then he was arrested on charges of assaulting a police officer and attempted rape.
My way ahead is long; I see no ending; yet high and low I'll search with my will unbending!
Github: https://github.com/youzhibing
Gitee: https://gitee.com/youzhibing
Back to the top.
Previously on
The Construction method of SpringApplication in springboot2.3 Source Code
Two main things have been done:
1. Speculate the type of application.
Determine the application type based on whether there is a class of the specified type under the classpath
There are three types of applications: NONE, SERVLET, REACTIVE,NONO for ordinary java applications, SERVLET for web projects based on servlet, and REACTIVE for reactive web application.
2. Obtain ApplicationContextInitializer and ApplicationListener instances
Find the URL (the path of the spring.factories file) of all META-INF/spring.factories under the classpath, and load all the contents of spring.factories (including various Initializer, ApplicationListener, AutoConfigure, Failure analyzers, etc.) into the cache of SpringFactoriesLoader
Then get the classes of type ApplicationContextInitializer and ApplicationListener from the cache and instantiate them, and then assign the instantiated sets to initializers and listeners of SpringApplication, respectively.
Run method of springboot2.3 source code (1): SpringApplicationRunListener
Two main things have been done:
1. Prepare the runtime listener: EventPublishingRunListener, and filter the listeners that match the ApplicationStartingEvent
2. Broadcast ApplicationStartingEvent events and trigger the corresponding event listeners
LoggingApplicationListener
Detect the log system in use
BackgroundPreinitializer
Another background thread performs time-consuming initialization
Run method of springboot2.3 source code (2): prepareEnvironment method
1. Get or create the environment
Create the corresponding environment according to the application type inferred in the SpringApplication construction method, generally speaking, the web environment: StandardServletEnvironment
2. Broadcast ApplicationEnvironmentPreparedEvent events and trigger the corresponding listeners
ConfigFileApplicationListener
Add a RandomValuePropertySource named random to environment
Add an OriginTrackedMapPropertySource named applicationConfig: [classpath: / application.yml] to environment
LoggingApplicationListener
Initialize the log system
3. Load externalized configured resources to environment
Including command line arguments, servletConfigInitParams, servletContextInitParams, systemProperties, sytemEnvironment, random, application.yml (.yaml / .xml / .properties), etc.
Run method of springboot2.3 source code (3): createApplicationContext method
1. Instantiate the application context
There are three types of applications, and there are also three corresponding contexts: NONE-> AnnotationConfigApplicationContext,SERVLET-> AnnotationConfigServletWebServerApplicationContext,REACTIVE-> AnnotationConfigReactiveWebServerApplicationContext;. Generally speaking, AnnotationConfigServletWebServerApplicationContext is created.
2. Instantiate AnnotatedBeanDefinitionReader, ClassPathBeanDefinitionScanner, and DefaultListableBeanFactory
AnnotatedBeanDefinitionReader is the annotated bean definition reader for programming the registration of annotated bean, and ClassPathBeanDefinitionScanner is the classpath bean definition scanner for detecting bean candidates on the classpath.
AnnotatedBeanDefinitionReade is used to load class-type configurations, and some BeanPostProcessor and BeanFactoryPostProcessor are pre-registered when it is initialized, and these processors are called in the following spring initialization process. ClassPathBeanDefinitionScanner is a scanner that scans annotated Bean definitions in the specified classpath and initializes comments that need to be scanned when it is initialized.
DefaultListableBeanFactory, which is what we call beanFactory, is used to register all bean definitions (bean definitions) and can also be used as a singleton bean factory.
Run method of springboot2.3 source code (4): prepareContext method
1. Apply some attributes in SpringApplication to the context
Environment, initializers and listeners in SpringApplication are applied to spring context
2. Broadcast ApplicationPreparedEvent events and trigger the corresponding event listeners
A PropertySourceOrderingPostProcessor instance is registered with the beanFactoryPostProcessors of context
Register a singleton bean called springBootLoggingSystem with beanFactory, that is, our log system bean
3. Load resources
Four methods are supported: Class, Resource, Package and CharSequence.
Class: the Bean definition in annotated form; AnnotatedBeanDefinitionReader handles it.
Resource: generally speaking, it refers to the xml bean configuration file, which is the xml configuration that we often use in spring. To put it simply: encapsulate the bean definition of xml into BeanDefinition and register it in beanFactory's BeanDefinitionMap; XmlBeanDefinitionReader is responsible for processing.
Package: scans the bean definition as a packet scan; ClassPathBeanDefinitionScanner handles it.
CharSequence: Class, Resource, or Package are matched in order to load, and whoever matches them is processed in the same way.
Springboot encourages the use of java classes to implement java bean definitions, so in springboot applications, we only need to focus on Class mode and Package mode.
Three main attributes have been added to context: beanFactory, beanFactoryPostProcessors, and applicationListeners
Back to the top.
Three events
ApplicationStartingEvent
Broadcast after listener registration, SpringApplication construction, and any other processing, triggering the corresponding event listener
ApplicationEnvironmentPreparedEvent
After the environment is created, the context is broadcast before the creation, triggering the corresponding event listener
ApplicationPreparedEvent
After the bean definition is loaded, the context refresh is broadcast before, triggering the corresponding event listener
ApplicationReadyEvent and ApplicationFailedEvent events will be involved in the follow-up, which will be explained in detail later.
For more details on the event mechanism, please visit here.
Back to the top.
Three cores
SpringApplication
One of the features of springboot, which is as follows
23. SpringApplication
23.1. Startup Failure
23.2. Customizing the Banner
23.3. Customizing SpringApplication
23.4. Fluent Builder API
23.5. Application Events and Listeners
23.6. Web Environment
23.7. Accessing Application Arguments
23.8. Using the ApplicationRunner or CommandLineRunner
23.9. Application Exit
23.10. Admin Features
It is also one of the more important features in springboot for booting and launching Spring applications from java main methods. In fact, what impresses me most is loading a series of classes from spring.factories, including Initializer, ApplicationListener, AutoConfigure, Failure analyzers and so on. The automatic configuration of springboot has already started at this time, and a series of AutoConfigure are obtained from spring.factories.
Environment:StandardServletEnvironment
Indicates that the current application environment mainly includes two aspects: profiles and properties;, such as local, operational test, pre-release, production environment, which we often talk about, can be configured through environment, and whether it is a web environment.
Generally speaking, our environment is StandardServletEnvironment, the standard servlet environment, which is what we often call web environment.
ApplicationContext:AnnotationConfigServletWebServerApplicationContext
The application context, which provides a central interface for the configuration of the application, provides the following:
1. The Bean factory method for accessing application components
2. The ability to load file resources
3. The ability to publish events to registered event listeners
4. Ability to parse messages and support internationalization
Wait, a series of functions.
AnnotationConfigServletWebServerApplicationContext is springboot's extension of spring application context and introduces some springboot content.
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.