理解Spring Boot中的pom配置
-
spring-boot-starter-parent : 是当前项目的父依赖
spring-boot-starter-parent 继承 spring-boot-dependencies
spring-boot-dependencies 里面定义了很多组件版本号,我们引用对应依赖时,不需要写标签
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</parent>
- spring-boot-starter-web spring-boot-starter-web
spring-boot-starter : 它是SpringBoot的场景启动器,它针对不同场景定义了很多不同的场景启动器,
你的项目需要使用哪些场景启动器,则直接依赖对应的启动器就可以了. spring-boot-starter-web 构建WEb项目,
比如:tomcat springmv
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- springboot单元测试启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- 导入配置文件处理器,在编写配置文件时就会提示
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
- 引入 jquery webjars
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
- 引入thymeleaf 启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- 热部署依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
- 如果使用了外置容器,则将tomcat启动器标识为provided
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--如果使用了外置容器,则将tomcat启动器标识为provided-->
<scope>provided</scope>
</dependency>
- 可以将当前项目打成一个jar包进行运行
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
本文主要解析Spring Boot项目中的pom文件,详细介绍了spring-boot-starter-parent作为父依赖的作用,如何通过它继承spring-boot-dependencies来管理组件版本。此外,还讲解了spring-boot-starter-web等场景启动器的应用,如构建Web项目、单元测试、配置文件处理、WebJar引入、Thymeleaf模板引擎、热部署以及外置容器和jar包运行的配置。
1万+

被折叠的 条评论
为什么被折叠?



