1、新建一个maven项目

2、在pom.xml中确认以下配置

<!-- SpringCloud 是聚合项目 需要在这里加上pom:手动添加-->
<packaging>pom</packaging>
3、SpringCloud的依赖管理

<!--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、建立插件

作用:
- 使用maven构建的项目可以直接使用maven build完成项目的编译、测试、打包,无需额外配置。
- build标签描述了如何编译及打包项目,具体的编译和打包工作是通过其中的plugin配置来实现的。当然,plugin不是必须的,即使不添加默认也会引入以下插件:

<!--建立插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
5、配置父包

<!--SpringBoot 父starter包 控制子项目jar版本号与父一致-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
6、配置一些全局必备依赖

<!--一些全局必备依赖-->
<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