SpringBoot入门
第一个SpringBoot程序
1.

2.

3.

4.

ps:可以阿里云镜像加速项目的构建。 (https://start.aliyun.com/)
SpringBoot快速启动
问题导入

打包过程
1.maven打包

2.找到打包好的jar包所在的文件夹,打开cmd

3.运行 java -jar
控制台打印如下信息

在pom中将skip标签属性设为false

重新打包,运行java -jar
成功运行
测试结果


SpringBoot到底干了什么?
为什么我们没有配服务器,没有导入依赖,SpringBoot程序仍能正常启动,相较于SSM项目配置的繁琐过程,SpringBoot到底做了什么?
我们打开SpringBoot程序的pom文件

管理依赖(dependencyManagement)
在这里有管理springboot的可选依赖,通过指定springboot的版本,这些依赖对应的版本可能大相径庭。
<dependencyManagement><dependencies>
<!-- 管理springboot的可选依赖,--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

引入依赖
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
名字中带有 -starter-??? 的称为启动依赖
以spring-boot-starter-web举例,打开它,发现里面有一堆依赖,包括我们运行web项目需要的服务器——tomcat,这就是我们不需要配服务器也能正常运行web项目的原因。

案例:切换服务器
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
<!-- 排除tomcat--><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions></dependency>
<!-- 引入jetty--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
在这里我们排除了tomcat服务器,引入了jetty服务器,不需要指定版本,因为他们的版本是由springboot的版本来指定的。
重新跑一下程序,一切正常

