Spring boot overview and introduction

1. Overview of Spring Boot

1.1. What is Spring Boot

Spring Boot is a sub-project of the Spring project. It belongs to the same product of Spring as the well-known Spring-framework: Introduction to Spring Boot on the home page, you can see the following section of introduction:

GET IS the Designed to Spring Boot you up and running Quickly AS AS Possible, with minimal Upfront
confifiguration of the Spring Spring Boot Takes opinionated View of Building Production's AN-READY.
Applications.
Translate:
designed to Spring Boot is for you as soon as possible Get up and running without the need to pre-configure Spring. Spring Boot uses a fixed way to build production-level applications. Generally speaking, Spring Boot is called the scaffolding of building programs, or it is convenient to build the engineering scaffolding based on Spring. Its main function is to help developers quickly build huge spring projects, and reduce all xml configurations as much as possible, so that they can be used out of the box and get started quickly, allowing developers to focus on business rather than configuration.

1.2. Why learn Spring Boot

Java has always been criticized for being bloated and troublesome. When we are still working hard to build the project, maybe the Python programmers have already written the functions.
The reason is two points:
complex configuration projects and various configurations are actually a loss during development, because we are thinking about Spring feature configuration and There is a need to switch thinking between solving business problems, so writing configuration squeezes time for writing application logic. One is that the dependency management of the chaotic dependency management project is also thankless. Deciding which libraries to use in the project is already a headache. You also need to know which version of these libraries will not conflict with other libraries. This problem is really tricky. Moreover, dependency management is also a loss, adding dependency is not writing application code. Once the wrong version is selected, the incompatibility issues that follow will undoubtedly be a productivity killer.
And Spring Boot makes all this a thing of the past!
Spring Boot simplifies the development of Spring-based applications. You only need to "run" to create an independent, production-level Spring application.
Spring Boot provides out-of-the-box settings for the Spring platform and third-party libraries (default settings are provided, and the package that stores the default configuration is the starter), so that we can simply start. Most Spring Boot applications require very little Spring configuration. We can use Spring Boot to create a java application and start it with java -jar, then we can get a production-level web project.

1.3. Features of Spring Boot

The main features of Spring Boot are:
creating independent Spring applications, providing all Spring developers with a very fast and widely accepted introductory experience.
Directly embedding in application servers, such as tomcat, jetty, undertow, etc.; no need to deploy war packages to
provide fixation The starter relies on to simplify component configuration; it can be used out of the box (starter is actually a jar
package provided by Spring Boot ), and you can quickly use it by setting parameters (.properties or .yml configuration files) by yourself.
Automatically configure Spring and other required third-party dependencies.
Provides some non-functional features common in large-scale projects, such as embedded servers, security, indicators, health detection, external configuration, etc. There
is absolutely no code generation, and no XML configuration .

2. Quick Start

Next, let's use Spring Boot to build a web project and experience the charm of Spring Boot!

2.1. Create Project

Create a new maven jar project: project information:
project path:
Insert picture description here

2.2. Add dependency

Many students here will have doubts. As mentioned earlier, one of the problems of traditional development is the confusion of dependency management. Why do we still need to manage dependency here? Doesn't
Spring Boot help us manage it?
Don't worry, our project has nothing to do with Spring Boot yet. Spring Boot provides a project called spring-boot-starter-parent
, which has managed the versions of various commonly used dependencies (not all). Our project needs to take this project as the parent project, so we
don’t have to worry about it. There is a problem with the version of the dependency, what dependency is needed, just import the coordinates directly!

2.2.1. Add parent project coordinates

Insert picture description here

2.2.2. Add web launcher

In order for Spring Boot to help us complete various automatic configurations, we must introduce the automatic configuration dependencies provided by Spring Boot, which we call the starter. Because
we are a web project, here we introduce the web launcher and add the following dependencies in the pom.xml file:
Insert picture description here

It should be noted that we did not specify the version information here. Because the parent project of Spring Boot has already managed the version.
At this time, we will find a lot of dependencies in the project.
Those dependencies are automatically introduced by Spring Boot based on the spring-boot-starter-web dependency, and all versions have been managed, and there will be no conflicts.

2.2.3. Manage jdk version

If we want to modify the jdk version of the Spring Boot project, we just need to simply add the following attributes. If there is no requirement, don't add it. Similarly
, add the following in the pom.xml file:
Insert picture description here

2.2.4. Complete pom file

The content of the pom.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.feng.demo</groupId> 
<artifactId>springboot-demo</artifactId> 
<version>1.0-SNAPSHOT</version> <properties>
<java.version>1.8</java.version> </properties> <parent>
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-parent</artifactId> 
 <version>2.1.5.RELEASE</version> </parent> 
 <dependencies> 
 <dependency> 
 <groupId>org.springframework.boot</groupId> 
 <artifactId>spring-boot-starter-web</artifactId>
  </dependency> 
  </dependencies> 
  </project>

2.3. Startup

The Spring Boot project can be started through the main function. We need to create a startup class:
write Application.java as follows:
Insert picture description here

2.4. Write the controller

Next, you can develop SpringMVC projects as before!
Write HelloController.java
Insert picture description here

2.5. Start the test

Next, run the main function and check the console:
Insert picture description here

And you can see the listening port information:
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/shuai_ge_feng/article/details/108523463