SpringBoot源码解读系列——开篇
什么是SpringBoot?
定义可以参考官网:SpringBoot官网,其定义通俗易懂,这里就不赘述。
官网也给出了一个通用的SpringBoot工程样例,其中包含了这么几个元素:
1、pom依赖
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.6.2
com.zengdan
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.3
mysql
mysql-connector-java
org.projectlombok
lombok
1.18.12
provided
com.alibaba
druid
1.2.1
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
org.xmlunit
xmlunit-core
org.mybatis
mybatis
3.4.6
org.springframework.boot
spring-boot-maven-plugin
org.projectlombok
lombok
2、启动类
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
3、简直、直接运行
通过java -jar xxx.jar(或者类似命令)就能直接运行Application。

上面可以看到,相比之前的Spring应用开发,SpringBoot相当简洁易用。那么,到底Spring Boot做了哪些工作降低了开发成本呢?这章和后续章节一一道来。
该系列文章,跟随SpringBoot版本升级持续更新,目前笔者所在的版本是SpringBoot2.6.3版本。