Spring boot quick start

Posted by Mistah Roth on Fri, 11 Feb 2022 14:47:18 +0100

Getting started SpringBoot

SpringBoot is a new framework provided by pivot team. It is designed to simplify the initial construction and development process of Spring applications

quick get start

1. Create a new module interface

2. Check SpringWeb under Web. For spring MVC dependency, click Finish

3. Write a simple business layer code

public class BookController {

    public String getById(){
        System.out.println("spring boot is running");
        return "spring boot is running";

4. Start springbootapplication Java startup class

5. Access URL:http://localhost:8080/books

The basic file of SpringBoot starter


Application class

Comparison between SpringBoot and Spring

Class / profileSpringBootSpring
Coordinates in pom fileCheck addAdd manually
web3.0 configuration classnothingHandmade
Spring / spring MVC configuration classnothingHandmade

Create and import the SpringBoot project on the official website

1. Official website address https://start.spring.io

2. Create a project on the official website and obtain the compressed package.

3. Unzip it to the local working directory

Alibaba cloud creates SpringBoot

Modify the Server URL to: http://start.aliyun.com

Creating projects in a non networked way

1. First, make sure that Maven warehouse has the following dependencies, manually create Maven project and write POM XML file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <relativePath/> <!-- lookup parent from repository -->




2. Write startup class

@SpringBootApplication//Necessary notes
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

3. Write the controller and access it through the browser

Introduction case analysis


SpringBoot can use parent dependency management < dependency manager > to version control the dependencies we need.

When some dependencies are not introduced into the Parent and you need them, you still need to specify the version by yourself. Pay attention to the problem of version conflict.

When we introduce dependency, we can directly use the version given by the parent project to achieve the effect of unified version.

Alibaba cloud inherits from the parent cloud. Inherit only once.

Note: different SpringBoot versions correspond to different dependent versions

■ Starter (dependency passing of SpringBoot)

Each Starter introduces the dependencies involved in related technologies. We just need to select the Starter reference according to the technology.

■ guided Application

Guide the main method in the class. We can find it by obtaining the return value of the following methods:

ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);

ConfigurableApplicationContext: context object, i.e. configuration file.

		ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
        BookController bean = run.getBean(BookController.class);

The initialization and configuration of the container are completed by the Application.

Note: by default, the annotation scanning range is the package where the startup class is located and its sub packages.

■ principle of starting Tomcat

1. Open POM XML, find the spring web starter and enter

2. Find the starter of tomcat and enter

3. There will be embedded tomcat dependencies

Remove tomcat test

1. Exclude tomcat dependency


2. Start the project

The tomcat server is no longer started.

3. Replace jetty server test

<!--introduce jetty-->

Three built-in servers of SpringBoot


Produced by apache, it has many fans and a wide range of applications. It is loaded with several heavy components.


Jetty is lighter and more scalable than Tomcat (compared with Tomcat). Google application engine (GAE) has been fully switched to jetty, and the load performance is far lower than Tomcat


undertow, load performance barely outperforms tomcat

Topics: Java Spring Spring Boot