Spring Boot 第一个程序_ide

📚
3.1. Build Systems
It is strongly recommended that you choose a build system that supports dependency management and that can consume artifacts published to the Maven Central repository.
强烈建议您选择支持依赖项管理的构建系统,并使用发布到Maven中央存储库的工件。
We would recommend that you choose Maven or Gradle.
我们建议您选择Maven或Gradle。
It is possible to get Spring Boot to work with other build systems (Ant, for example), but they are not particularly well supported.
可以让Spring Boot与其他构建系统(例如Ant)一起工作,但是它们并没有得到特别好的支持。
3.1.1. Dependency Management
Each release of Spring Boot provides a curated list of dependencies that it supports.
Spring Boot的每个版本都提供了它所支持的依赖项列表。
In practice, you do not need to provide a version for any of these dependencies in your build configuration, as Spring Boot manages that for you.
实际上,您不需要在构建配置中为这些依赖项提供版本,因为Spring Boot会为您管理它。
When you upgrade Spring Boot itself, these dependencies are upgraded as well in a consistent way.
当您升级Spring Boot本身时,这些依赖项同样也会升级。

2、源码解析

对注解解析过程不熟悉的可以参考:​​Spring注解解析过程​​

@SpringBootConfiguration

Spring Boot 第一个程序_ide_02

Spring Boot 第一个程序_spring_03


Spring Boot 第一个程序_spring_04


Spring Boot 第一个程序_ci_05


Spring Boot 第一个程序_ci_06


Spring Boot 第一个程序_spring_07


Spring Boot 第一个程序_ide_08

​SpringFactoriesLoader​​​ 加载 ​​META-INF/spring.factories​

springboot 启动源码解析

springboot 主启动类:

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

controller

@RestController
public class FirstController {
@RequestMapping("/hello")
public String hellowold(){
return "helloworl!";
}
}

springboot启动后,为什么在浏览器输入地址 ​​http://localhost:8080/hello​​中直接访问?

一定是启动了了spring容器和web服务器,我们下面就通过源码来分析一下这个过程。

我们先看看 ​​SpringApplication.run​​ 方法,点击进去看到

public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
// 1、 new SpringApplication(...):Spring Boot 环境初始化和一些准备工作
// 2、run : 启动容器、web服务器等
return new SpringApplication(primarySources).run(args);
}

run:1237, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
main:13, FirstSpringbootApplication (com.yh.stu.springboot)