准备工作
版本:jdk1.8
开发工具:idea
SpringBoot版本:2.1.7.RELEASE
SpringCloud版本:Greenwich.SR2
创建SpringCloud微服务项目
采用的是Maven分包分模块的架构,一个Project带着多个Module模块。
1. 创建父工程
- 新建父工程microservicecloud,切记是pom模式,主要是定义POM文件,将后续各个子模块公用的jar包等统一提取出来,类似一个抽象父类。

创建主工程,选择maven,直接next
- 填写相关的项目相关信息

填写相关的项目相关信息.png
- 填写项目名和项目位置

填写项目名和项目位置.png
- 主项目创建完毕,修改主项目pom文件。因为主项目是pom模式,只是为了统一处理各个子model的依赖。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.galax</groupId>
<artifactId>microservicecloud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!--各个父工程的子模块-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-cloud-dependencies.version>Greenwich.SR2</spring-cloud-dependencies.version>
<spring-boot-dependencies.version>2.1.7.RELEASE</spring-boot-dependencies.version>
</properties>
<!--依赖管理器,子model按需引用即可,子模块无需声明版本号-->
<dependencyManagement>
<dependencies>
<!--多继承 spring cloud,相当于<parent>标签-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--多继承 spring boot,相当于<parent>标签-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<build>
<finalName>microservicecloud</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimit>$</delimit>
</delimiters>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. 创建子模块
- 创建子model

创建子模块

选择Spring Initializr
需要注意的是,若是出现Initialization failed for 'https://start.spring.io异常。解决方案:
将地址 'https://start.spring.io' 里的 https 变为 http

创建时异常解决方案
- 填写项目信息

image.png
- 创建相应的模块

image.png
- 填写项目名以及项目位置

image.png