Do you know the purpose of Java Springboot

  • 2021-11-13 01:42:16
  • OfStack

Directory Spring-boot Purpose Spring How to simplify the development of the first spring-boot program summary

Spring-boot Purpose

Spring was created to solve the complexity of enterprise application development and simplify development

How Spring Simplifies Development

1. Lightweight and Minimally Invasive Programming Based on POJO

2. Loose coupling through IOC, dependency injection (DI), and interface-oriented

3. Declarative programming based on (AOP) and conventions

4. Reduce style codes based on sections and templates

Microservices

The first spring-boot program

The official provides a fast-generated website! idea integrates this site

1 can be downloaded in official website and imported into idea development (official website)

2 Create an springboot project directly using idea (1 creates directly on idea)

Automatic configuration principle

Automatic configuration: pom. xml

spring-boot-dependencies: Core dependency in parent project

When we write or introduce 1 springboot dependencies, we don't need to specify a version because of these version repositories

Starter


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

Starter: To put it bluntly, it is the scene starter of SpringBoot

For example, spring-boot-starter, he will help us automatically import all dependencies of web environment

springboot will turn all functional scenarios into starters one by one

If we want to use any function, we only need to find the corresponding launcher. start

Main program


// Indicate that this class is 1 A springboot Application 
@SpringBootApplication
public class SpringBoot01HelloworldApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBoot01HelloworldApplication.class, args);
    }
}

@SpringBootConfiguration	springboot Configuration of 
		 Down 
	@configuation	spring Configuration class 
		 Down 
	@Component : The explanation is 1 A spring Component 
@EnableAutoConfiguration	 Automatic configuration 
	@@AutoConfigurationPackage Automatic Configuration Package 
	@Import(@AutoConfigurationPackage.Registrar.class): Automatically configure package registration 
	@Import({AutoConfigurationImportSelector.class}) Automatically import selections ( Component )	
	List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);
	 Get all the configurations 

Get candidate configurations


protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
    List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
    Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
    return configurations;
}

META-INF/spring. factories Automatic Configuration Core Files


Properties properties = PropertiesLoaderUtils.loadProperties(resource);  All resources are loaded into the configuration class 

Conclusions:

springboot all auto-configuration is in start-up scan and load spring-factories all auto-configuration classes are in it, but not 1 will take effect, to determine whether the condition is established, to determine whether it is established, as long as the import of the corresponding start, there will be a corresponding starter, with the starter, our auto-assembly will take effect, and then 2 configuration is successful

1. When springboot is started, get the specified value from the path of the class/META-INF/spring. factories;

2. Import these auto-configuration classes into the container auto-configuration classes will take effect and help us to auto-configure

From 3.1, we need to configure things automatically, and now springboot has done it for us

4. Everything that integrates javaEE, solutions, and auto-configurations is in spring-boot-autoconfigure-2. 3.7. RELEASE. jar

5. He will return all the components that need to be imported as class names, and these components will be added to the container;

6. There are also many xxxAutoConfiguration files in the container (@ Bean), which import all the components needed for this scenario and configure them automatically, @ Configuration, javaConfig!

7. With the automatic configuration class, we are relieved of the task of writing configuration files manually


SpringApplication.run(SpringBoot01HelloworldApplication.class, args);
 SpringApplication Load the main class 
  This class mainly does the following 4 One thing 
 1. Determine the type of ordinary project applied or web Project 
 2. Find and load all available initializers, set to initializers Attribute 
 3. Find out all application listeners and set them to listeners Attribute 
 4. Inferred and set main Method, find the main class to run 

javaConfig @Configuration @Bean

Docker: Processes

In the tializers property

3. Find out all the application listeners and set them to the listeners property

4. Infer and set the definition class of the main method, and find the main class to run


javaConfig @Configuration @Bean
Docker: Process 

Summarize

This article is here, I hope to give you help, but also hope that you can pay more attention to this site more content!


Related articles: