SpringBoot-快速入门


官方文档

Getting Started


快速入门

1. 创建Maven项目

例如创建一个名为 springboot-helloworld 的项目

2. 配置环境

添加继承的父工程

    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.6
    

添加类路径依赖项


    
        org.springframework.boot
        spring-boot-starter-web
    


3. 编写代码

创建一个名为src/main/java/MyApplication.java的文件来包含以下代码:

import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;


@RestController
@EnableAutoConfiguration
public class MyApplication {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

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

}

4. 运行工程

编写一个可运行类

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

@SpringBootApplication
public class Application {

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

}

访问 localhost:8080 就会看见hello world的字样


起步依赖分析

spring-boot-starter-parentspring-boot-starter-web

其中定义了各种技术的版本信息,组合了一套最优搭配的技术版本
在各种starter中,定义了完成该功能需要的坐标合集,其中大部分版本信息来自于父工程