The first section

Basic features and concepts of SpringBoot

Build Anything with Spring Boot: Spring Boot is the starting point for building all Spring-based applications. Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring. Spring Boot is the starting point for Spring development, reducing the amount of configuration required for Spring development. Conventions over configurations, also known as programming by convention, is a software design paradigm. For example, when the entity class is User, our corresponding database table is User, and this convention that follows a certain rule is convention over configuration. The concept SpringBoot is based on Spring and improves on some of Spring’s weaknesses (Spring’s configuration files are heavyweight and need to be scanned for a large number of XML files each time it is started). Spring Boot no longer requires us to configure Spring, Spring MVC and other dependencies in pom.xml. It is a reference that packages these dependencies together. Advantage 2: Automatic configuration. In SpringBoot, we no longer need to configure a large number of beans. Beans can be automatically injected into the IOC container and retrieved by @Autowired annotation.

In the second quarter

Build the SpringBoot project

Build using Spring Initializr



Select Spring Initializr, which will display the following when networked, and select the JDK development version.



The Spring Boot version is 2.5.2 (the default option is the latest and most stable). Check Spring Web to add the Spring MVC dependency.

In the third quarter

Basic usage and hot deployment of SpringBoot

The basic case

Spring Boot’s automatic classes should be at the parent of the Controller package, because the boot class scans the current boot class’s package and its children after it is started. For example, it belongs to the same hierarchy as com.hellojava.

Hot deployment

The first step is to add dependencies to the pom.xml file



<dependency>

  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>

</dependency>

Then open the file-> settings-> Compiler in the IDEA tool

Then Shift + Ctrl + Alt +/ Open

Click Registry and check the following options

The fourth quarter,

SpringBoot’s global configuration file

Application. Properties configuration file format: person.id=1 person.name=tom person.hobby=study,play person.map.k1 = v1 person.map.k2 = v2 person.pet.name = dog person.pet.type = dog

Person: id: 2 Name: Lisi Hobby: [Play, Study] Map: {v1: k1,v2: k2} Pet: {type: dog,name: Tom} Person: id: 2 Name: Lisi Hobby: [Play, Study] Map: {v1: k1,v2: k2} Pet: {type: dog,name: Tom}

If there are more than one global configuration files, they will be loaded with the following priority, and the subsequent ones will override the previous application*.yml application*.yaml application*.properties

Section 5

Note the difference between ConfigurationProperties and Value

The entity class of the @ConfigurationProperties annotation, which must have a set method to take effect, is the annotation for the entire class. Easily batch inject custom property values from a configuration file into multiple corresponding properties of a Bean object. @ConfigurationProperties(prefix = “person”) public class Person { private int id; Public void setId(int id) {this.id = id; this.id = id; }}

The @Value annotation is provided by the Spring framework to read the property values from the configuration file and inject them into the corresponding properties of the Bean object one by one. The Spring Boot framework inherits the @Value annotation by default from the Spring framework. This annotation can also be used to read and inject configuration file property values in the Spring Boot framework. The @Value annotation is on a property and does not identify a particular type of property, such as a map, an object, etc. Automatically help you implement set and get methods. public class Person { @Value(“${person.id}”) private int id; }

Section 6

Custom configuration and custom parameters

Custom configuration files

SpringBoot eliminates most of the manual configuration in a project, and for some specific cases, you can modify the global configuration file

Almost any configuration can be written in the application.peroperties file. SpringBoot automatically loads the global configuration file, eliminating the need to load it manually. However, if we customize the configuration files, SpringBoot will not recognize them and we will need to load them manually.

The first step:

Create the test.properties file under the Resources package

The second step:

Create a test entity class

Step 3:

Run the test under TEST

Random number parameter setting and parameter application: ${random. Value} my.number=${random. Int} my. bigNumber =${random. Long} // My.uuid =${random. Uuid} my.number.less. Than. Ten =${random My.number.in. range=${random. Int [1024,65536]} // Set the range between [1024,65536] and [1024,65536]

Parameter reference: app.name= myApp app.description=${app.name} is good