环境
JDK1.8
IntelliJ IDEA
Maven-3.3.9
项目结构
sca
···sca-common·························································公共模块
······sca-common-base··············································公共基础模块
···sca-job······························································· 分布式任务调度模块
···sca-api································································业务接口定义模块
······sca-api-normal···················································标准业务接口模块
······sca-api-taobao···················································淘宝订单业务接口模块
···sca-rest·······························································服务实现模块
······sca-rest-normal··················································标准业务实现模块
······sca-rest-taobao··················································淘宝订单业务实现模块
···sca-gateway·························································路由网关模块
创建根项目
打开IDEA,选择File > New > Project
选择Maven>Next,然后输入自己喜欢的GroupId 和 ArtifactId
修改 sca 主模块的 pom.xml
<?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.ldh</groupId>
<artifactId>sca</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<description>springCloud-alibaba</description>
<modules>
<module>sca-common</module>
<module>sca-rest</module>
<module>sca-api</module>
<module>sca-job</module>
<module>sca-gateway</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.11.RELEASE</version>
</parent>
<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>
<java.version>1.8</java.version>
<!-- 版本属性 -->
<spring-cloud-alibaba.version>2.1.0.RELEASE</spring-cloud-alibaba.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>
<spring-platform.version>Cairo-SR8</spring-platform.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- spring-cloud-alibaba 总依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--支持Spring Boot 2.1.X-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--Greenwich.RELEASE-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--
Spring IO Platform,简单的可以认为是一个依赖维护平台,该平台将相关依赖汇聚到一起,针对每个依赖,都提供了一个版本号
完整的依赖列表 https://docs.spring.io/platform/docs/current/reference/html/appendix-dependency-versions.html
-->
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>${spring-platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 子项目公共依赖的jar包 -->
<dependencies>
<!-- nacos discovery -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- lombok插件 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- Swagger SpringBoot -->
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
</dependencies>
</project>
其中SpringBoot选择2.1.11.RELEASE 版,SpringCloud选择Greenwich.RELEASE版,两者版本匹配度参考如下表格
Spring Cloud | Spring Boot |
---|---|
Angel版本 | 兼容Spring Boot 1.2.x |
Brixton版本 | 兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x |
Camden版本 | 兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x |
Dalston版本、Edgware版本 | 兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x |
Finchley版本 | 兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x |
Greenwich版本 | 兼容Spring Boot 2.1.x |
分别创建其余子模块
其中注意创建子Module的时候,建议Project Name 最好和 ArtifactId 保持一致。
最终项目结构如下图