Spring Boot startup steps + underlying principles + common annotations

1. The basic startup process of Spring Boot is described as follows:

1) Load classes based on configuration (read the class at the specified location into memory through ClassLoader ->The bottom layer calls IO through threads
to read from disk to memory).

2) Analyze the class (create bytecode object-Class type, obtain the configuration information through reflection).

3) For the object with the specified configuration (for example, described by spring-specific annotations), store its configuration information (with the help of
BeanDefinition object storage).

4) Construct an instance of the class (Bean object) based on the configuration of the class in the BeanDefinition object, and manage the bean object
(may be stored in the bean pool). 

2. Spring Boot underlying principles + knowledge points

*Underlying Principle*
The core concept of Spring Boot: Agree on the approximate configuration and agree on a certain naming convention. Function development can be completed without configuration

/**SpringBoot是什么?*/
   SpringBoot是一个框架,一种全新的编程规范,它的产生简化了框架的使用,所谓简化是指简化了Spring众多框架中所需的大量且繁琐的配置文件,所以SpringBoot是一个服务于框架的框架,服务范围是简化配置文件。
    
/**SpringBoot可以做什么?*/
    让文件配置变的相当简单、让应用部署变的简单(SpringBoot内置服务器Tomcat、Jetty等,并装备启动类代码),可以快速开启一个Web容器进行开发。
       
/**SpringBoot特点?*/  
	搭建项目快,几秒钟就可以搭建完成;
	Spring Boot让配置变的简单,Spring Boot的核心理念:约定大约配置,约定了某种命名规范,可以不用配置,就可以完成功能开发,比如模型和表名一致就可以不用配置,直接进行CRUD(增删改查)的操作,只有表名和模型不一致的时候,配置名称即可;
	内嵌容器,省去了配置Tomcat的繁琐;
	让测试变的简单,内置了JUnit、Spring Boot Test等多种测试框架,方便测试;
	方便监控,使用Spring Boot Actuator组件提供了应用的系统监控,可以查看应用配置的详细信息。
 
/**SpringBoot的好处*/       
    其实就是简单、快速、方便!平时如果我们需要搭建一个 Spring Web 项目的时候需要怎么做呢?

	配置 web.xml,加载 Spring 和 Spring mvc
	配置数据库连接、配置 Spring 事务
	配置加载配置文件的读取,开启注解
	配置日志文件

	配置完成之后部署 Tomcat 调试
    
/**Spring Boot包含两种格式的配置文件:*/
    yml		 data:
  	  	 		 app:
        			appKey: Test
    
    properties
                data.app.appKey = Test

 

3.Spring BootCommon annotations

1.@SpringBootApplication: Startup class annotation
    Essentially composed of 3 annotations, namely
    @Configuration
    @EnableAutoConfiguration
    @ComponentScan
2. @SpringBootTest: Test class annotation

3.@ComponentScan: The function of @ComponentScan is to scan the current package and sub-packages, and register classes annotated with @Component, @Controller, @Service, @Repository and other annotations into the container for easy calling.

4.@SpringBootConfiguration: Annotated on a certain class, indicating that this is a SpringBoot configuration class

5.@EnableAutoConfiguration: Import AutoConfigurationImportSelector with the help of @Import, and load all bean definitions that meet the automatic configuration conditions into the IoC container
Use SpringFactoriesLoader to load beans in AutoConfigurationImportSelector a>

4. Spring Boot default port number + how to modify the port number

Default port number 8080  

The file application.properties in the src/main/resources directory and configure it to override the default configuration of spring boot
#Specify the port number
1. (Modify port number) server.port=8090

Guess you like

Origin blog.csdn.net/m0_71202849/article/details/126857568