本篇主要说明以下内容:
1.SpringBoot2.x中Maven的配置内容,即:pom.xml
的内容说明
1 Maven依赖的配置方式
使用Maven来配置SpringBoot2.x,有两种方式:
1.SpringBoot2.x的父依赖,在使用生成的项目中,会是这种方式
2.项目独立引入SpringBoot2.x的pom依赖
1.1 SpringBoot2.x父依赖
这种方式,项目完整的pom.xml文件,如下:
4.0.0 cc.anxminise.spblearn application 0.0.1-SNAPSHOT jar application Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.6.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
以上关键的配置,如下:
xml节点名称 | 说明 |
---|---|
parent | 标明项目按SpringBoot2.x默认配置来处理 |
plugin.spring-boot-maven-plugin | 对SpringBoot项目进行打包 |
如果项目中已经有自己的parent
,此时,可以使用项目独立引入
的方式。
1.2 项目独立引入
这种方式是通过pom文件中的dependencyManagement标签
来实现SpringBoot的引入,完整的pom.xml文件如下:
4.0.0 cc.anxminise.spblearn application 0.0.1-SNAPSHOT jar application Demo project for Spring Boot org.springframework.boot spring-boot-dependencies 2.0.6.RELEASE pom import UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin cc.anxminise.learnspboot.Application repackage
以上关键的配置,如下:
xml节点名称 | 说明 |
---|---|
dependencyManagement.dependencies.dependency.spring-boot-dependencies | 标明项目按SpringBoot2.x默认配置来处理 |
plugin.spring-boot-maven-plugin | 对SpringBoot项目进行打包,这里需要手动配置应用的启动类 |
这种方式,相对而言,更为的灵活。