项目创建与统一依赖管理
1. 项目结构
sca-study
|- pom.xml
|- user-center
|- src
|- pom.xml
|- content-center
|- src
|- pom.xml
2. 版本使用列表
| 名称 | 版本 |
|---|---|
| JDK | 1.8.0_212 |
| Spring Boot | 2.1.6.RELEASE |
| Spring Cloud | Greenwich.SR3 |
| Spring Cloud Alibaba | 2.1.0.RELEASE |
3. 根项目配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.xam.study</groupId>
<artifactId>sca-study</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring cloud alibaba -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>user-center</module>
<module>content-center</module>
</modules>
</project>
4. 创建微服务项目
分别创建user-center和content-center两个微服务项目,并为微服务指定端口和名称
user-center的application.yml配置
server:
port: 18082
spring:
application:
# 指定微服务名称,微服务间调用时需要使用
name: user-center
content-center的application.yml配置
server:
port: 18081
spring:
application:
# 指定微服务名称,微服务间调用时需要使用
name: content-center