SpringBoot2 ---- write a HelloWorld

1, What is SpringBoot?

         Spring Boot is a new framework provided by pivot team. It is designed to simplify the initial construction and development process of new spring applications. The framework uses a specific way to configure, so that developers no longer need to define templated configurations.

2, Characteristics

  1. Create a stand-alone Spring application
  2. Embedded Tomcat, no need to deploy WAR file
  3. Simplify Maven configuration
  4. Auto configure Spring
  5. Provide production ready functions such as indicators, health checks and external configurations
  6. There is absolutely no code generation and no configuration requirements for XML  

3, Write Spring Boot's Hello World

        1. Environment for installing Spring Boot

                Create a Maven project (I use IDEA2019.3.x), or directly create a Spring Initializr project. You can directly write a helloworld file. You can view:
                SpringBoot is created directly without configuring the pom.xml path

          Install the SpringBoot environment using the pom.xml file

pom.xml file:





Previously, when learning spring MVC, our packaging method was


When writing a SpringBoot project, you can change it to jar


In this way, it is convenient to package and send to others after the completion of later projects, so there is no need to configure this environment.

After the environment required in the pom.xml package is written, wait for the download. After the download, the environment configuration is completed.

         2. You are now ready to create a java file to write

  SpringBoot is a further simplification of other Spring design patterns. There is no need to configure mapper.xml or a separate tomcat. Just use one controller to execute.

  The properties file in the resources is used to configure the port number of tomcat and some other variable quantities.

In the HelloController.java file, it is the same as the previous spring MVC. Use @ RequestMapping to set a path for the Hello method


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class HelloController {

    public String hello(){
        return "hello";


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

 * Main program class
 * @SpringBootApplication:This is a SpringBoot application

public class MySpringBootTest {
    public static void main(String[] args) {

         3. Run

        Run the MySpringBootTest file directly

  This indicates that the project was created successfully.

You can view it in the browser  


Tags: Java Spring Spring Boot SpringBoot2

Posted on Mon, 01 Nov 2021 10:59:43 -0400 by chyan