不分轻重难易,碰到哪个说哪个!
(一)parent父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Ctrl+左键 进入spring-boot-starter-parent,发现它还源于于另一个parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
爸爸的爸爸叫爷爷!再Ctrl+左键 进入spring-boot-dependencies,发现里面有一个 属性:
<properties>
<activemq.version>5.15.13</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.81</appengine-sdk.version>
<artemis.version>2.12.0</artemis.version>
<aspectj.version>1.9.6</aspectj.version>
<-......此处省略100行 /->
<webjars-locator-core.version>0.45</webjars-locator-core.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
<xmlunit2.version>2.7.0</xmlunit2.version>
</properties>
这里定义了许许多多的依赖的版本号。
这个东西,也就是”爷爷“ 我们称它为”版本仲裁中心“,从此我们添加的依赖不需要指定版本号,版本仲裁中心自己决定要用哪个版本。(注意:这里可能会有特例)
(二)添加依赖
我们所有的第三方依赖都必须添加到这个目录下:
<dependencies>
<- 依赖/->
</dependencies>
接下来看看我遇到的第一个依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
spring-boot-starter-web这句代码可以分为两个部分
前部分:spring-boot-starter,这东西叫:场景启动器
后部分:-web , 这东西是指:指定场景,这里就是web场景
Ctrl+左键 进入spring-boot-starter-web,发现它的源文件有这么多依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>2.3.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.8.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.8.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
这东西怎么理解呢?其实也就是spring-boot-starter场景启动器帮我们启动了web模块开发所需要的最基本最常见的依赖,不再需要我们去逐一添加依赖。
注: 场景启动器可以启动更多更多的场景,见官方文档。
(三)要将项目打包成可执行jar的必备标签
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>