SpringCloud学习
前言
springboot现在已经非常的成熟,而springcloud的经过这几年的发展也已经开始越发的火热,许许多多的在大厂都在开始使用springcloud,像著名的阿里,京东等
一、简述springcloud
简述:
如今的互联网时代,我们无时无刻的不在使用着电子产品,如何是一个万物互联的时代,但是我们不能做到不同厂商的设置之间实现互联,而每一个springboot就相当于一个电子产品(也可以是一个技术),我们与希望所有的springboot能够忽略厂商从而进行互联,由此springcloud就产生了,它能够帮助我们忽略掉个个springboot之间的差异,从而进行互联。
曾经我们用springboot来做各种服务,现在springboot可以做了一个功能单元,然后用springcloud进行整合,所以springcloud其实就是多的springboot的集合。
springcloud分为:
服务注册与发现,服务调用,服务熔断,负载均衡,服务降级,服务消息队列,配置中心管理,服务网关,服务监控,全链路追踪,自动化构建部署,服务定时任务调度操作等
京东微服务架构:
springcloud主流的技术栈:
小结:
springcloud=分布式微服务架构的一站式解决方案,是多种微服务架构落地技术的集合体,俗称微服务全家桶.
二、Springboot和Springcloud版本选择
我们选择SpringBoot2.X版和SpringCloud H版
这个前面是springcloud版本,后面是对应要选择的springboot的版本,springcloud对springboot有一定的版本要求,"x"表示任意的意思,例如“2.6.x”表示可以是"2.6.1"也可以是"2.6.2"等
详细的springboot与springcloud的版本关系表
{
"git": {
"branch": "881e633a6a33776174ee1e0274016acc0715f7c7",
"commit": {
"id": "881e633",
"time": "2022-03-28T14:06:08Z"
}
},
"build": {
"version": "0.0.1-SNAPSHOT",
"artifact": "start-site",
"versions": {
"spring-boot": "2.6.5",
"initializr": "0.13.0-SNAPSHOT"
},
"name": "start.spring.io website",
"time": "2022-03-28T14:09:11.256Z",
"group": "io.spring.start"
},
"bom-ranges": {
"azure": {
"3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"3.5.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1",
"3.14.0": "Spring Boot >=2.5.0.M1 and <2.7.0-M1"
},
"codecentric-spring-boot-admin": {
"2.4.3": "Spring Boot >=2.3.0.M1 and <2.5.0-M1",
"2.5.5": "Spring Boot >=2.5.0.M1 and <2.6.0-M1",
"2.6.2": "Spring Boot >=2.6.0.M1 and <2.7.0-M1"
},
"solace-spring-boot": {
"1.1.0": "Spring Boot >=2.3.0.M1 and <2.6.0-M1",
"1.2.1": "Spring Boot >=2.6.0.M1 and <2.7.0-M1"
},
"solace-spring-cloud": {
"1.1.1": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"2.1.0": "Spring Boot >=2.4.0.M1 and <2.6.0-M1",
"2.3.0": "Spring Boot >=2.6.0.M1 and <2.7.0-M1"
},
"spring-cloud": {
"Hoxton.SR12": "Spring Boot >=2.2.0.RELEASE and <2.4.0.M1",
"2020.0.5": "Spring Boot >=2.4.0.M1 and <2.6.0-M1",
"2021.0.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-M3",
"2021.0.0-M3": "Spring Boot >=2.6.0-M3 and <2.6.0-RC1",
"2021.0.0-RC1": "Spring Boot >=2.6.0-RC1 and <2.6.1",
"2021.0.1": "Spring Boot >=2.6.1 and <2.6.7-SNAPSHOT",
"2021.0.2-SNAPSHOT": "Spring Boot >=2.6.7-SNAPSHOT and <3.0.0-M1",
"2022.0.0-M1": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
},
"spring-cloud-gcp": {
"2.0.8": "Spring Boot >=2.4.0-M1 and <2.6.0-M1",
"3.1.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1"
},
"spring-cloud-services": {
"2.3.0.RELEASE": "Spring Boot >=2.3.0.RELEASE and <2.4.0-M1",
"2.4.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"3.3.0": "Spring Boot >=2.5.0-M1 and <2.6.0-M1",
"3.4.0": "Spring Boot >=2.6.0-M1 and <2.7.0-M1"
},
"spring-geode": {
"1.3.12.RELEASE": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"1.4.13": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"1.5.11": "Spring Boot >=2.5.0-M1 and <2.6.0-M1",
"1.6.5": "Spring Boot >=2.6.0-M1 and <2.7.0-M1",
"1.7.0-M3": "Spring Boot >=2.7.0-M1 and <3.0.0-M1",
"2.0.0-M2": "Spring Boot >=3.0.0-M1 and <3.1.0-M1"
},
"vaadin": {
"14.8.6": "Spring Boot >=2.1.0.RELEASE and <2.6.0-M1",
"23.0.3": "Spring Boot >=2.6.0-M1 and <2.8.0-M1"
},
"wavefront": {
"2.0.2": "Spring Boot >=2.1.0.RELEASE and <2.4.0-M1",
"2.1.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"2.2.2": "Spring Boot >=2.5.0-M1 and <2.7.0-M1"
}
},
"dependency-ranges": {
"native": {
"0.9.0": "Spring Boot >=2.4.3 and <2.4.4",
"0.9.1": "Spring Boot >=2.4.4 and <2.4.5",
"0.9.2": "Spring Boot >=2.4.5 and <2.5.0-M1",
"0.10.0": "Spring Boot >=2.5.0-M1 and <2.5.2",
"0.10.1": "Spring Boot >=2.5.2 and <2.5.3",
"0.10.2": "Spring Boot >=2.5.3 and <2.5.4",
"0.10.3": "Spring Boot >=2.5.4 and <2.5.5",
"0.10.4": "Spring Boot >=2.5.5 and <2.5.6",
"0.10.5": "Spring Boot >=2.5.6 and <2.5.9",
"0.10.6": "Spring Boot >=2.5.9 and <2.6.0-M1",
"0.11.0-M1": "Spring Boot >=2.6.0-M1 and <2.6.0-RC1",
"0.11.0-M2": "Spring Boot >=2.6.0-RC1 and <2.6.0",
"0.11.0-RC1": "Spring Boot >=2.6.0 and <2.6.1",
"0.11.0": "Spring Boot >=2.6.1 and <2.6.2",
"0.11.1": "Spring Boot >=2.6.2 and <2.6.3",
"0.11.2": "Spring Boot >=2.6.3 and <2.6.4",
"0.11.3": "Spring Boot >=2.6.4 and <2.6.7-SNAPSHOT",
"0.11.4-SNAPSHOT": "Spring Boot >=2.6.7-SNAPSHOT and <2.7.0-M1"
},
"okta": {
"1.4.0": "Spring Boot >=2.2.0.RELEASE and <2.4.0-M1",
"1.5.1": "Spring Boot >=2.4.0-M1 and <2.4.1",
"2.0.1": "Spring Boot >=2.4.1 and <2.5.0-M1",
"2.1.5": "Spring Boot >=2.5.0-M1 and <2.7.0-M1"
},
"mybatis": {
"2.1.4": "Spring Boot >=2.1.0.RELEASE and <2.5.0-M1",
"2.2.2": "Spring Boot >=2.5.0-M1"
},
"camel": {
"3.5.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"3.10.0": "Spring Boot >=2.4.0.M1 and <2.5.0-M1",
"3.13.0": "Spring Boot >=2.5.0.M1 and <2.6.0-M1",
"3.16.0": "Spring Boot >=2.6.0.M1 and <2.7.0-M1"
},
"picocli": {
"4.6.3": "Spring Boot >=2.4.0.RELEASE and <3.0.0-M1"
},
"open-service-broker": {
"3.2.0": "Spring Boot >=2.3.0.M1 and <2.4.0-M1",
"3.3.1": "Spring Boot >=2.4.0-M1 and <2.5.0-M1",
"3.4.0-M2": "Spring Boot >=2.5.0-M1 and <2.6.0-M1"
}
}
}
所以我们选择
我们为什么选择springboot 2.3.12.RELEASE版本呢,是因为这是官网推荐的
我们点击红色的ReferenceDoc文件
官网推荐我们使用springboot 2.3.12.RELEASE
三、子项目的创建与初始化
在父项目中新建一个cloud-provider-payment8081项目.
在父项目中右击,选择new->module
设置pom.xml文件
<artifactId>cloud-provider-payment8001</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--mysql-connector-java-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--jdbc-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
选择maven项目直接点击下一步
在rescources中添加配置文件(application.yml)并进行相应的配置
#端口号
server:
port: 8081
#项服务名称
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 当前数据源操作类型
driver-class-name: org.gjt.mm.mysql.Driver # mysql驱动包 com.mysql.jdbc.Driver
url: jdbc:mysql://124.221.175.238:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
mybatis:
mapperLocations: classpath:mapper/*.xml
type-aliases-package: com.atguigu.springcloud.entities # 所有Entity别名类所在包
添加启动类PaymentMain8081
设置启动程序,将将他设置成启动类:
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);
}
四、cloud-provider-payment8081子项目编写服务
先创建所需的数据表-payment:
CREATE TABLE `payment` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`serial` varchar(200) DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
新建payment表的实体类entity
因为我不想再去写set/get方法,所以我们去添加插件-lombok
file->setting->plugins中在marketplace中查询lombok
点击install安装他,然后再安装插件mybatisx,和lombok一样的步骤,然后再重启idea软件
然后创建Payment实体类:
package com.atguigu.springcloud.entities;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data//get,set方法
@AllArgsConstructor//全参构造方法
@NoArgsConstructor//无参构造方法
//实现Serializable序列化接口,为以后进行分布式配置准备
public class Payment implements Serializable {
private Long id;
private String serial;
}
因为我们想进行前后端分离开发,所以我们需要让后端返回的是一个json数据类型的数据,所以我们需要创建一个json返回工具类-CommonResult:
我们采用范型,这样我们以后传递的数据是什么类型,data就可以自动变成什么类型
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@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层的接口
@Mapper
public interface PaymentDao {
public int create(Payment payment);
public Payment getPaymentgetbyid(@Param("id") Long id);
}
编写mybatis的接口映射文件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">
//**********************
</mapper>
<?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" >
<!-- com.atguigu.springcloud.dao.PaymentDao是指此文件和哪个数据库操作接口进行关系-->
<mapper namespace="com.atguigu.springcloud.dao.PaymentDao">
<!-- create是和关系的接口文件下的create接口方法进行关联-->
<insert id="create" parameterType="com.atguigu.springcloud.entities.Payment"
useGeneratedKeys="true" keyProperty="id"
>
insert into payment(serial) value (#{serial});
</insert>
<!-- 设置查询的返回值如何与实体类进行映射-->
<resultMap id="BaseResultMapper" type="com.atguigu.springcloud.entities.Payment">
<result property="id" column="id" jdbcType="BIGINT"></result>
<result property="serial" column="serial" jdbcType="VARCHAR"></result>
</resultMap>
<!-- PaymentDao的getPaymentbyid-->
<select id="getPaymentgetbyid" parameterType="Long" resultMap="BaseResultMapper">
select * from payment where id=#{id}
</select>
</mapper>
创建service层的接口 PaymentService
import com.atguigu.springcloud.entities.Payment;
import org.apache.ibatis.annotations.Param;
public interface PaymentService {
public int create(Payment payment);
public Payment getPaymentgetbyid(@Param("id") Long id);
}
创建他的实现类PaymentServiceImpl:
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
private PaymentDao paymentDao;
@Override
public int create(Payment payment) {
return paymentDao.create(payment);
}
@Override
public Payment getPaymentgetbyid(Long id) {
return paymentDao.getPaymentgetbyid(id);
}
}
实现前端调用类PaymentController:
-
在类上添加@RestController注解,有了这个注解,前端就可以通过调用ajxs之类的方式来调用这个接口
-
在类上添加@Slf4j,我们可以在执行程序时进行日志打印
-
new一个PaymentService接口,在spring中接口是可以被new出来的,他会找他的实现类,而添加上@Resource这个注解就可以直接像c语言中一样 类型 变量名;来创建一个变量。
-
新建一个方法叫public CommonResult create(Payment payment),意思就下传递过来的是一个Payment对象数据,这个上方法的返回值是CommonResult,而在这个方法上添加@PostMapping这个注解就是和javaweb中我们使用Servlet时给方法添加@Webservlet(value="方法别名")的效果一样并且将这个方法设置成Post请求方法。
-
调用PaymentService类型变量的create方法,如果他的返回值是大于0的数据就返回{返回值200,返回提示信息“插入成功”,插入结果}的对象,如何插入不成功就返回{返回值444,返回提示信息“插入失败”,null}
-
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.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; //这个注解是@RequestMapping和@Controller的合体版,他可以将这个类设置成controller层的类,还可以让这个类返回的数据是json数据 @RestController //打印日志的注解 @Slf4j public class PaymentController { @Resource private PaymentService paymentService; @PostMapping(value = "/payment/create") public CommonResult create(Payment payment) { int result = paymentService.create(payment); log.info("*******插入的结果:"+result); if(result>0) { return new CommonResult(200,"插入数据库成功",result); } else { return new CommonResult(444,"插入数据库失败",null); } } }
查询方法同上(因为查询是get请求,所以注解是@GetMapping):
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.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; //这个注解是@RequestMapping和@Controller的合体版,他可以将这个类设置成controller层的类,还可以让这个类返回的数据是json数据 @RestController //打印日志的注解 @Slf4j public class PaymentController { @Resource private PaymentService paymentService; @PostMapping(value = "/payment/create") public CommonResult create(Payment payment) { int result = paymentService.create(payment); log.info("*******插入的结果:"+result); if(result>0) { return new CommonResult(200,"插入数据库成功",result); } else { return new CommonResult(444,"插入数据库失败",null); } } @GetMapping(value = "/payment/get/{id}") public CommonResult getpaymentbyid(@PathVariable("id") Long id) { Payment payment = paymentService.getPaymentgetbyid(id); if(payment!=null) { return new CommonResult(200,"查询成功",payment); } else { return new CommonResult(444,"未查询到,查询id:"+id,null); } } }
对业务进行测试:
我们用apifox来对接口进行请求测试
如何我们给/payment/create发送一个json串的数据,我们就必须要给方法中添加一个@RequestBod注解
五、热部署Devtools
热部署:在平时我们写一个项目的时候只要一修改项目中的一行代码,我们就需要将项目重新跑一个,但是热部署可以直接一边修改一边运行项目
在需要进行热部署的项目模块中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
添加对应的插件(在父工程中添加插件)
<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>
更改idea相关设置
在设置中找到如图的选项,并将圈起来的选项选中变成打勾状态
通过ctrl+alt+shift+/打开操作页面,点击Registry
找到此项然后将其勾选上
选中项目设置
将下面选中的设置成如下样子
六、创建服务消费者模块 cloud-consumer-order80
和上一个8001模块一样的创建
添加如下依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
添加配置文件
service:
port: 80
spring:
application:
name: could-consumer-order80
创建启动类-OrderMain80,并将其设置成启动类:
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-privider-payment8001模块中的两个关于payment的查询和添加方法,所以我们需要Payment和CommonResult这两个类,我们将这两个类放到如今OrderMain80模块下面的entities包中
实现模块与模块之间的通信(一个springboot可以像前端一样调用另一个springboot项目的接口,并获取到返回数据)
方法一:
使用restTemplate
先自己创建一个restTemplate的配置类ApplicationContextConfig
我们需要告诉springboot这个类是一个配置类,所以我们需要用@SpringBootConfiguration
添加一个bean对象,让他返回restTemplate对象
@Bean
public RestTemplate getRestTemplate()
{
return new RestTemplate();
}
步骤:
-
定义一个变量,用来存储用调用服务的地址
-
注入一个RestTemplate对象;
-
创建一个post请求方法
-
在里面调用restTemplate.postForObject,restTemplate.postForObject(接口访问地址,要向接口发送的数据,返回的数据类型)
restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonResult.class); postForObject------这个是针对post请求的,get请求有get请求的方法 PAYMENT_URL+"/payment/create"----------拼接后就是接口的访问地址 payement---------就是要向接口发送的数据,可以是任何一个对象 CommonResult.class--------告诉要返回的数据的类型是CommonResult对象类型
这个是get的调用方法
@GetMapping("/consumer/payment/get/{id}") public CommonResult<Payment> get(String id) { return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class); }
package com.atguigu.springcloud.controller; import com.atguigu.springcloud.entities.CommonResult; import com.atguigu.springcloud.entities.Payment; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; @RestController @Slf4j public class OrderController { // 定义一个要调用服务的地址的变量 public static final String PAYMENT_URL="http://localhost:8001"; @Resource private RestTemplate restTemplate; @PostMapping("/consumer/payment/create") public CommonResult<Payment> create(@RequestBody Payment payment) { return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonResult.class); } @GetMapping("/consumer/payment/get/{id}") public CommonResult<Payment> get(@PathVariable("id") String id) { System.out.println("执行get"+id); return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class); } }
然后重新启动PaymentMain8001和OrderMain80两个类,
如果OrderMain80中出现了找不到
这两个类的话就需要到maven工具中去点击install一下,在install前先要将test执行去掉点一个圈起来的标识,test变成了中间有一条横线的
然后再点击install
消费者接口的测试:
此处有坑:在进行测试时我们的设置的启动端口是80,但是我们电脑的80端口可能会被占用,所以我们需要去看一个我们服务实际启动的端口是多少
由此我们可以看出这个服务实际上是启动在8080端口的
七、功能模块的公共类的优化
在我们的这两个springboot项目中都有Payment和CommonResult这两个类,如果我们将来的代码越写越多将会出现许多的重复的类,所以我们需要对他们进行整合
我们创建一个新的模块,名字就cloud-api-commons,他用来存放我们用的公共的类
添加相应的依赖
<dependencies>
<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>
<!--糊涂工具包-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
将原来项目上的那两个类去除掉
在原来的cloud-povider-payment8001项目中添加一个依赖
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
cloud-consumer-order80模块也是如此
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
然后再到cloud-api-commons处打开maven管理工具
重启两个服务后再进行接口测试,一样的可以进行