Current location - Health Preservation Learning Network - Slimming men and women - Spring Boot notes
Spring Boot notes
1, ApplicationContextInitializer, which is used to initialize before the Spring context is refreshed. At this point, the ApplicationContext has been created, but there is no refresh (), and the ApplicationContextInitializer performs the initial operation on the ApplicationContext.

2.SpringApplicationRunListener, which broadcasts the events in each cycle of the ApplicationContext, so that the ApplicationListener can monitor these events.

3.runner, Spring context post-processing Runner can be an implementation class of two interfaces: org. In fact, there is no difference between springframework.boot.applicationrunnerorg.springframework.boot.commandlinerunner. It's just that the parameters accepted by the run method in the interface are different. One is a packaged ApplicationArguments type, and the other is a direct string indefinite array type. Therefore, you can choose the corresponding interface as needed.

When SpringBoot starts, no matter what method is called, an instance of SpringApplication will be constructed, and then the run method of this instance will be called, which is to start SpringBoot.

Before calling the run method, that is, when constructing the SpringApplication, initialization will be performed, and the following things will be done during initialization:

After the construction of SpringApplication is completed, call the run method to start the SpringApplication. When the run method is executed, it will do the following:

Enable auto configuration import selector is introduced in the @ springboottaping tag, in which the selectImports () method is called. Call the org. springframework.boot.autoconfigure.enableautoconfigurationimportselector # getCandidateconfigurations method in the method. SpringFactoryLoader is used to load files with EnableAutoConfiguration as keywords in the spring.factories file in the META-INF folder. The loaded files are all java config configuration files (default configuration) and @ conditional (class

A relatively basic and important class, running and loading the spring.factories file in MATE-INF.

The @Conditional tag is the root of all conditional tags. The conditional tags in the source code are parsed by ConditionEvaluator, as follows: org.springframework.context.annotation.annotated bean defines the reader # registerbean (java.lang.class

When annotationconfigurationapplicationcontext is initialized, classes such as configurationclasspostprocessor and autowired annotationbeanpostprocessor are registered. as follows

ConfigurationClassPostProcessor is a BeanFactoryPostProcessor, so it will post-process the BeanDefinitionRegistry or BeanDefinition after creation (BeanFactory has been created in the refresh method, depending on where it runs).

The import parsing principle is based on ConfigurationClassPostProcessor, and the loading process of ConfigurationClassPostProcessor refers to the above. It mainly analyzes why the @import tag can call the selector method org. springframework.context.annotation.configurationClassPostProcess when it introduces configuration. Or # postprocesssideditionregistry org.springframework.context.annotation.configurationclasspostprocessor # processconfigbeandeditions org . spring framework . context . annotation . configurationclassparser # parse(Java . util . set & lt; org . spring framework . beans . factory . config . bean definition holder & gt; ) org.springframework.context.annotation.configurationclassparser # processDeferredimportselectors Then, call the selectImports method as follows.