1.pom文件
SpringBoot项目的pom文件中多出了<parent>元素配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<parent>元素配置的实际上是一个springboot项目,项目名称spring-boot-starter-parent,我们自己创建的springboot项目实际上是spring-boot-starter-parent项目的子项目。
<parent>配置父项目,之所以在自己创建springboot项目中的pom文件中配置<parent>配置父项目,是为了从父项目中继承某一些元素。
查看spring-boot-starter-parent项目,打开了spring-boot-starter-parent项目的pom文件,发现spring-boot-starter-parent项目中也配置了<parent>元素,得到spring-boot-dependencies父父项目
查看spring-boot-dependencies项目中得到了
<properties>
<activemq.version>5.16.4</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.95</appengine-sdk.version>
<artemis.version>2.19.1</artemis.version>
<aspectj.version>1.9.7</aspectj.version>
<assertj.version>3.21.0</assertj.version>
.............
</properties>
<properties>元素中子元素名称都是<xxxx.version>是我们所创建的项目的所有依赖包版本。
还得到了下面
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-amqp</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-blueprint</artifactId>
<version>${activemq.version}</version>
</dependency>
...................
</dependencies>
</dependencyManagement>
上面的<dependencies>元素中配置的是我们所创建项目的所有依赖包的导入。
这个【spring‐boot‐dependencies】项目实际是用来真正管理SpringBoot应用里面的所有依赖包。
有了【spring‐boot‐dependencies】项目以后我们新建的SpringBoot项目所需要依赖包就不需要再配置版本和<dependencies>元素导入依赖,从【spring‐boot‐dependencies】项目中继承就可以了。
只要我们再创建springboot项目的时候,选择对应的springboot版本,那么这个版本对应的就会将我们所需要的依赖包导入,所以我们自己就不需要再去配置导入依赖包。springboot版本独赢的依赖包都是配置好的,不会出现版本冲突。
2.SpringBoot启动器
我们在创建springboot项目的时候,选择对应的springboot版本,此时springboot就会将我们创建spring项目所需要的所有依赖包导入
当我构建程序的时候,这些依赖包有的会用到,有的不会用到,此时springboot版本就会将这些依赖包按照不同的使用场景/功能,划分成很多组,将实现某一个具体功能/适用于某一个具体开发场景的依赖包归结到一起,被归结在一起实现某一个具体功能/适用于某一个具体开发场景的依赖包就组成了一个启动器。
我们在创建自己具体功能的时候吗,只需要导入对应功能/对应场景的启动器就可以。此时我们就不用担心因为实现的功能时而将某一个依赖包遗漏的情况。
基本的启动器
SpringBoot应用启动器基本的一共又44中,具体如下:
1)spring-boot-starter:这是Spring Boot的核心启动器,包含了自动配置、日志和YAML。
2)spring-boot-starter-actuator:帮助监控和管理应用。
3)spring-boot-starter-amqp:通过spring-rabbit来支持AMQP协议(Advanced Message Queuing Protocol)。
4)spring-boot-starter-aop:支持面向方面的编程即AOP,包括spring-aop和AspectJ。
5)spring-boot-starter-artemis:通过Apache Artemis支持JMS的API(Java Message Service API)。
6)spring-boot-starter-batch:支持Spr