Spring Boot quickly build entry program

1. Quickly build an entry program

first step

Added Spring-Boot-starter-parent dependency [web dependency of parent project]

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.7.RELEASE</version>
</parent>

Second step

Added Spring-Boot-starter-web dependency [web dependency of subproject]

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

third step

Use @SpringBootApplication to annotate and create the main program class

@SpringBootApplication
public class HelloApplication {
    public static void main(String[] args){
        SpringApplication.run(HelloApplication.class);
    }
}

the fourth step

Create Controller HelloWorld access program

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public String hello(){
        return "This is my first SpringBoot Application";
    }
}

Insert picture description here

Two, two methods of SpringBoot startup

1. Run the Main method directly

2. Start with plugin

  • The first step is to add the MAVEN plugin spring-boot-maven-plugin
  • The second step is to add < configuration > and < mainClass > to the MAVEN plugin to configure and start the main function

Third, use application.properties to configure the project

properties和yml项目常用的两种文件配置方式,properties的优先级高于yml

  • Spring Boot automatically generates the application.properties configuration file in the Resources directory
    Configuration format: key = value
  • Spring Boot automatically generates the application.yml configuration file in the Resources directory
    Configuration format: key: value (a space after the colon)
Published 395 original articles · won 130 · 200,000 views +

Guess you like

Origin blog.csdn.net/qq_40507857/article/details/103688955