1、新建一个maven项目
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/4f2b0c16b3034bdfa9f270e9ee60f716.png?x-oss-process=image/resize,w_1400/format,webp)
2、在pom.xml中确认以下配置
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/25cc9db4c75e455db7a8b08ca1047cd2.png?x-oss-process=image/resize,w_1400/format,webp)
<!-- SpringCloud 是聚合项目 需要在这里加上pom:手动添加-->
<packaging>pom</packaging>
3、SpringCloud的依赖管理
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/6750631a8acd4b45bf27a9cd2aa2f9b6.png?x-oss-process=image/resize,w_1400/format,webp)
<!--SpringCloud的依赖管理-->
<dependencyManagement>
<!--依赖关系-->
<dependencies>
<!--依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
4、建立插件
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/e79961e4f0bc482f9e76129874c2ad6d.png?x-oss-process=image/resize,w_1400/format,webp)
作用:
- 使用maven构建的项目可以直接使用maven build完成项目的编译、测试、打包,无需额外配置。
- build标签描述了如何编译及打包项目,具体的编译和打包工作是通过其中的plugin配置来实现的。当然,plugin不是必须的,即使不添加默认也会引入以下插件:
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/6aa88ecd7fd64f63903e75350dc7bdff.png?x-oss-process=image/resize,w_1400/format,webp)
<!--建立插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
5、配置父包
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/2658ff67339e4eeca1721ae5e7247f3c.png?x-oss-process=image/resize,w_1400/format,webp)
<!--SpringBoot 父starter包 控制子项目jar版本号与父一致-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
6、配置一些全局必备依赖
![image.png image.png](https://ucc.alicdn.com/pic/developer-ecology/13996f8f16d645a3972b9433ce742561.png?x-oss-process=image/resize,w_1400/format,webp)
<!--一些全局必备依赖-->
<dependencies>
<!--SpringBoot自动配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<!--SpringBoot启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--单元测试:这个可以不必备-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
上一篇:从零搭建微服务SpringCloud(一)了解什么是SpringCloud
下一篇:从零搭建微服务SpringCloud(三)创建SpringCloud注册中心-Eureka