微服务架构编码构建
一、IDEA新建project工作空间
1. 微服务cloud整体聚合父工程Project【父工程Project空间新建】
-
New Project
-
聚合总工程名字
-
Maven选版本
-
字符编码
-
注解生效激活
-
java编译版本选8
-
File Type过滤【选做】
-
删除src目录
2. 父工程POM文件
<?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.atguigu.springcloud</groupId>
<artifactId>cloud2020</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 表明当前工程是一个总的父工程-->
<packaging>pom</packaging>
<!-- 统一管理jar包版本 -->
<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>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<lombok.version>1.16.18</lombok.version>
<mysql.version>5.1.47</mysql.version>
<druid.version>1.1.16</druid.version>
<mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
</properties>
<!-- <dependencyManagement>标签:锁定版本(保证子模块的版本号与父工程也就是当前工程保持一致) + 子模块不用写groupId和version【建子模块的时候不用写】 -->
<!-- 常用在父工程中 -->
<dependencyManagement>
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud Hoxton.SR1-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud alibaba 2.1.0.RELEASE-->
<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>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
3. Maven工程落地细节复习
- <dependencyManagement>标签和<dependencies>标签的区别:
Maven使用dependencyManagement元素来提供了一种管理依赖版本号的方式。
通常会在一个组织或者项目的最顶层的父POM中看到dependencyManagement元素。
使用pom.xml中的dependencyManagement元素能让所有在子项目中引用一个依赖而不用显式的列出版本号。
Maven会沿着父子层次向上走,直到找到一个拥有dependencyManagement元素的项目,然后它就会使用这个
dependencyManagement元素中指定的版本号。
这样做的好处就是:如果有多个子项目都引用同一样依赖,则可以避免在每个使用的子项目里都声明一个版本号,这样当想升级或切换到另一个版本时,只需要在顶层父容器里更新,而不需要一个个子项目的修改;外如果某个子项目需要另外的一个版本,只需要声明version就可。
dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。
如果不在子项目中声明依赖,不会从父项目中继承下来的;只有在子项目中写了该依赖项,且没有指定具体版本,才会从父项目中继承该项,并耳version和scope都读取自父pom;
如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
将父工程的POM文件改为上述内容后,可能会出现POM爆红,Dependency ‘xxx‘ not found的情况,这是因为<dependencies>标签外层套了<dependencyManagement>标签,<dependencies>标签内部声明的依赖不会进行引入,将<dependencyManagement>注释掉,刷新POM文件即可正常引入,引入后在解开注释即可。
参考网站:https://www.jianshu.com/p/f727211244fc
- maven中跳过单元测试
- 验证本地的Maven与Idea的整合是否成功
执行项目的install操作,看到success就是成功了
二、Rest微服务工程构建
初步的工程架构如下:
注:80和8001指的是端口
1. cloud-provider-payment8001微服务提供者支付Module模块
工作中常见的开发模式
如何构建一个微服务模块
1.建module【微服务的子模块】
注:Linux中部署时一般按照端口号进行部署
创建了子模块之后,可以看到父工程的POM中增加了一部分内容,这就是当前工程的子模块
位置上可以做如下调整
注:一般将g、a、v和packaging放在一起,其他内容继续放
2.改POM【子模块的pom文件】
<?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">
<parent>
<artifactId>cloud2020</artifactId>
<groupId>com.atguigu.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<!-- 由于父工程中使用了<dependencyManagement>标签,子模块中可以不用写groupId和version-->
<artifactId>cloud-provider-payment8001</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<!-- 写了就用子工程的版本,不写就用父工程控制的版本-->
<version>1.1.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3.写YML/properties【application.yml / application.properties】
#子模块/resource/application.yml
#凡是微服务,一定要有服务端口号和微服务名称
#服务端口号
server:
port: 8001
#微服务名称
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.gjt.mm.mysql.Driver
url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
mybatis:
mapperLocations: classpath:mapper/*.xml
type-aliases-package: com.atguigu.springcloud.entities # 所有Entity别名类所在包
4.主启动
在子模块中创建启动类
package com.atguigu.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PaymentMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8001.class, args);
}
}
5.业务类
-
建表SQL
CREATE TABLE payment
(
id
bigint NOT NULL AUTO_INCREMENT,
serial
varchar(255) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
2. entitles
主实体类【Payment】
```java
package com.atguigu.springcloud.entities;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* Serializable: 序列化 分布式可能会用到
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment implements Serializable {
private Long id;
private String serial;
}
JSON封装体实体类【CommonResult】
package com.atguigu.springcloud.entities;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* JSON封装体
* @param <T>
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {
private Integer code;
private String message;
private T data;
public CommonResult(Integer code,String message){
this(code,message,null);
}
}
-
dao
接口【PaymentDao】
package com.atguigu.springcloud.dao; import com.atguigu.springcloud.entities.Payment; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; /** * 这里的注解使用的是@Mapper而不是@Repository,@Repository在插入数据时可能有问题 */ @Mapper public interface PaymentDao { public int create(Payment payment); public Payment getPaymentById(@Param("id") Long id); }
Mapper映射文件【PaymentMapper.xml】
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.atguigu.springcloud.dao.PaymentDao"> <!-- 由于application.xml中配置了mybatis.type-aliases-package,parameterType可以直接写类名--> <insert id="create" parameterType="Payment" useGeneratedKeys="true" keyProperty="id"> insert into payment(serial) values(#{serial}); </insert> <resultMap id="BaseResultMap" type="com.atguigu.springcloud.entities.Payment"> <id column="id" property="id" jdbcType="BIGINT"/> <id column="serial" property="serial" jdbcType="VARCHAR"/> </resultMap> <!-- 这里一般会写resultMap--> <select id="getPaymentById" parameterType="Long" resultMap="BaseResultMap"> select * from payment where id = #{id} </select> </mapper>
-
service
接口【PaymentService】
package com.atguigu.springcloud.service; import com.atguigu.springcloud.entities.Payment; import org.apache.ibatis.annotations.Param; public interface PaymentService { // Service中的方法一般同Dao中保持一致(方法名、参数等) public int create(Payment payment); public Payment getPaymentById(@Param("id") Long id); }
实现类【PaymentServiceImpl】
package com.atguigu.springcloud.service.impl; import com.atguigu.springcloud.dao.PaymentDao; import com.atguigu.springcloud.entities.Payment; import com.atguigu.springcloud.service.PaymentService; import org.springframework.stereotype.Service; import javax.annotation.Resource; @Service public class PaymentServiceImpl implements PaymentService { // @Resource也可完成依赖注入 @Resource private PaymentDao paymentDao; @Override public int create(Payment payment) { return paymentDao.create(payment); } @Override public Payment getPaymentById(Long id) { return paymentDao.getPaymentById(id); } }
-
controller
package com.atguigu.springcloud.controller; import com.atguigu.springcloud.entities.CommonResult; import com.atguigu.springcloud.entities.Payment; import com.atguigu.springcloud.service.PaymentService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @Slf4j @RestController public class PaymentController { @Resource PaymentService paymentService; /** * 路径命名规则:/实体类名/操作 * @param payment * @return */ @PostMapping("/payment/create") public CommonResult create(Payment payment){ int result = paymentService.create(payment); //工作中一般会打印日志,而不是使用System.out log.info("*****插入数据:" + result); if (result > 0){ return new CommonResult(200, "插入数据成功", result); }else { return new CommonResult(444, "插入失败"); } } @GetMapping("/payment/get/{id}") public CommonResult getPaymentById(@PathVariable("id")Long id){ Payment payment = paymentService.getPaymentById(id); log.info("*****查询数据:" + payment); if (payment != null){ return new CommonResult(200, "查询成功", payment); }else { return new CommonResult(444, "插入失败"); } } }
6.测试
测试中要注意的点:
①Post请求通过Postman工具进行测试
②写完接口要自测通过
③通过Postman发送Post请求,可以通过以下的方式发送
④Run 运行空间和Run DashBoard【或Services】 运行空间的区别:
当我们只有一个模块(微服务)时,默认开启的是Run窗口
随着模块(微服务)个数的增加,idea会自动从Run切换到Run DashBoard【或Services】这个工作空间
如果idea并没有自动切换,可以通过以下方式配置开启
修改idea的workpace.xml的方式来快速打开Run DashBoard【或Services】窗口
填入以下内容:
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
如果上述方案不行,尝试在顶部添加如下内容
<component name="RunDashboard">
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
<option name="contentProportion" value="0.22874807" />
</component>
参考网站:https://baijiahao.baidu.com/s?id=1706362488557741076&wfr=spider&for=pc
2. 热部署Devtools
仅开发阶段开启,正式上线后必须关闭。
2.1 Adding devtools to your project
想修改哪个模块的时候自动部署就加在哪个模块的pom中
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
2.2 Adding plugin to your pom.xml
下一段配置黏贴到父工程当中的pom里
<build>
<!-- <finalName>:值为当前工程的名字,该配置项可加可不加-->
<!-- <finalName>cloud2020</finalName>-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
2.3 Enabling automatic build
选中"A"、"D"、"B"、"C"几项
2.4 Update the value of
idea中按下Ctrl+Shift+Alt+/
,点击register
,选中compiler.....和action.....两项
![](https://gitee.com/honourer/picturebed/raw/master/SpringCloud/图像 (2).png)
![](https://gitee.com/honourer/picturebed/raw/master/SpringCloud/图像 (3).png)
2.5 重启Idea使配置生效
如果Devtools配置成功,项目启动后会有如下标识
3. cloud-consumer-order80微服务消费者订单Module模块
-
建module【微服务的子模块】
方法同cloud-provider-payment8001模块的构建
-
改pom
<?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"> <parent> <artifactId>cloud2020</artifactId> <groupId>com.atguigu.springcloud</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-consumer-order80</artifactId> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
-
写YML
#客户端一般设置端口为80,这样在访问网址时不需要加端口号,默认就是80端口 server: port: 80
-
主启动
package com.atguigu.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class OrderMain80 { public static void main(String[] args) { SpringApplication.run(OrderMain80.class, args); } }
-
业务类
-
实体类
直接拿cloud-provider-payment8001中的两个实体类来用【CommonResult和Payment】
-
RestTemplate
现在客户端消费者的微服务【订单模块】要调用微服务提供者【支付模块】的微服务,需要RestTemplate完成该功能。
注:RestTemplate是对HttpClient的封装,实际就是一种调用接口方式的封装,用于完成不同服务间的远程调用,类似的技术还有httpClient、Webservice、RPC访问。RestTemplate提供了多种便捷访问远程Http服务的方法,是一种简单便捷的访问restful服务模板类,是Spring提供的用于访问Rest服务的客户端模板工具集。
RestTemplate的使用参考:
首先要在客户端微服务中创建一个配置类,用于向Spring容器中注入RestTemplate,以供Controller调用。
package com.atguigu.springcloud.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @Configuration public class ApplicationContextConfig { @Bean public RestTemplate getRestTemplate(){ return new RestTemplate(); } }
-
Controller
package com.atguigu.springcloud.controller; import com.atguigu.springcloud.entities.CommonResult; import com.atguigu.springcloud.entities.Payment; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; @RestController public class OrderController { public static final String PAYMENT_URL = "http://localhost:8001"; @Resource private RestTemplate restTemplate; // 客户端的Controller中一般给路径加一个/consumer前缀用以区分微服务提供者的接口路径 @GetMapping("/consumer/payment/create") public CommonResult<Payment> create(Payment payment){ // 使用restTemplate访问restful接口非常的简单粗暴无脑: // (url, requestMap, ResponseBean.class)这三个参数分别代表REST请求地址、请求参数、HTTP响应转换被转换成的对象类型。 return restTemplate.postForObject(PAYMENT_URL+ "/payment/create", payment, CommonResult.class); } @GetMapping("/consumer/payment/get/{id}") public CommonResult<Payment> getPayment(@PathVariable("id")Long id){ return restTemplate.getForObject(PAYMENT_URL+ "/payment/get/" + id, CommonResult.class); } }
-
-
测试
先启动cloud-provider-payment8001【服务提供者】
再启动cloud-consumer-order80【服务消费者】
通过Post /payment/create?serial=111的方式请求服务生产者的接口,数据依然能够保存成功,为什么?
通过Post /consumer/payment/create?serial=111的方式请求服务消费者的接口,数据却不能够保存成功,为什么?
4. 工程重构
4.1 观察问题
当前工程中存在一个问题,entities在支付模块和订单模块中各有一份,一模一样,代码冗余,接下来需要将entities拿出来,打成jar包
![](https://gitee.com/honourer/picturebed/raw/master/SpringCloud/图像 (4).png)
当前工程是maven聚合父工程的方式构建的,这种情况进行重构就需要将重复部分提到一个公共的工程中,供其他工程使用,该公共工程不仅用于存放共用代码,对于一些公共接口、第三方接口、工具类都可以放在该工程中,并且该工程是不对外暴露的,没有服务端口。
4.2 创建公共工程cloud-api-commons
通常公共的工具类会放到公共工程中
-
建module
参考其他两个模块创建module即可
-
改POM
<?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"> <parent> <artifactId>cloud2020</artifactId> <groupId>com.atguigu.springcloud</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-api-commons</artifactId> <dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- 引入hutool工具包,包含日期格式化等,常用的工具包--> <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.1.0</version> </dependency> </dependencies> </project>
-
抽取公共entities到cloud-api-commons中
在cloud-api-commons中创建相同的entities包路径,将公共的entities放到该路径下【Copy Reference + Show in Explorer大法】
-
maven clean + maven install
将cloud-api-commons进行maven打包、发布、上传到共用的本地库中供其他两个工程调用
注:上述操作可能出现如下警告,不会影响结果。
Some problems were encountered while building the effective model for com.atguigu.springcloud:cloud-api-commons:jar:1.0-SNAPSHOT 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ com.atguigu.springcloud:cloud2020:1.0-SNAPSHOT, D:\Data\work_demo\source_code\sn_two\cloud2020\cloud2020\pom.xml, line 99, column 15 It is highly recommended to fix these problems because they threaten the stability of your build. For this reason, future Maven versions might no longer support building such malformed projects.
如果想解决这个警告,参考https://blog.csdn.net/shyg866/article/details/108113891
-
改造订单模块和支付模块【一个一个改造】
-
删除两个模块中的entities
-
在两个模块各自的POM中引入cloud-api-commons
<!-- 引入自定义的api通用包--> <dependency> <groupId>com.atguigu.springcloud</groupId> <artifactId>cloud-api-commons</artifactId> <version>${project.version}</version> </dependency>
-