• Chat springboot

The biggest advantage of Spring Boot is convention over configuration.

It configures the use of many frameworks by default, just as Maven integrates all jars and Spring Boot integrates all frameworks.

In the old Spring framework, you had to configure everything for your application. There were a lot of configuration files, such as XML or meta-annotations. This was one of the main problems Spring Boot solved


  • Springboot boot process

Blog.csdn.net/qq_32101993…

SpringBoot is started by the new SpringApplication() instance, which does several things:

1. Configure properties. 2. Obtain listeners and publish application startup events. Initialize input parameters 4. Configure the environment and output the banner 5. Create context 6. Preprocessing context 7. Refresh Context 8. Refresh Context 9. Publish event 10 that the application has been started. Publish the application startup completion eventCopy the code


  • Principle of automatic assembly

The SpringBoot project starts with the @SpringBootApplication annotation, which consists of three annotations:

  • @Configuration

  • @ComponentScan

  • @EnableAutoConfiguration

One @ EnableAutoConfiguration is to realize the automatic configuration of entrance, the annotations by @ Import annotations Import AutoConfigurationImportSelector, Load the meta-INF/Spring.Factories configuration information in this class. Then screen out the data with EnableAutoConfiguration as key, load into IOC container, realize automatic configuration function!


  • How does the Spring Boot Starter work

Starter can be thought of as a Maven dependency group, and introducing the group name introduces all of the dependency packages for the technology.

Spring Boot does a few things when it starts up:

  • (1) Spring Boot looks for the resources/ meta-INF /spring.factories file in the Starter package that the project relies on during startup.

  • The AutoConfigure class is loaded according to the Spring. factories configuration

  • ③ Automatically configure and inject the Bean into the Spring Context according to the conditions of the @Conditional annotation

To sum up, Spring Boot reads the configuration information of the Spring Boot Starter according to the convention, initializes resources based on the configuration information, and infuses the resources into the Spring container. In this way, after Spring Boot is started, all resources are ready, and the corresponding Bean resources can be directly injected during use.


  • How does Tomcat work in SpringBoot

SpringBoot is started by the new SpringApplication() instance, which does several things:

1. Configure properties. 2. Obtain listeners and publish application startup events. Initialize input parameters 4. Configure the environment and output the banner 5. Create context 6. Preprocessing context 7. Refresh Context 8. Refresh Context 9. Publish event 10 that the application has been started. Publish the application startup completion eventCopy the code

Starting Tomcat is “refresh context” in step 7. The startup of Tomcat is mainly to initialize two core components, Connector and Container. A Tomcat instance is a Server, and a Server contains multiple services, that is, multiple applications. Each Service contains multiple connectors (Connetor) and a Container, which has multiple child containers: Engine, Host, Context, and Wrapper. The other containers can have multiple connectors.