[3-03-01].第07节:搭建服务 - 服务重构cloud-consumer-ocommon

SpringCloud学习大纲


一、观察问题:

  • 1.两个服务模块中具有重复的代码部分 ,为了简化开发,对象项目进行重构:

二、编码实现重构:

2.1.创建公共模块:

第1步:建模块:

  • 模块名为cloud-api-commons,在此模块中对外暴露通用的组件、api、接口、工具类

第2步:改pom

  • pom依赖如下所示:
xml 复制代码
<dependencies>
        <!--SpringBoot通用依赖模块-->
        <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.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!--hutool-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
        </dependency>
    </dependencies>

第3步:entities:

第4步:maven命令:


2.2.改造订单80和支付8001模块:

  • 1.删除原有的entities和统一返回体等内容,然后在pom文件中引入commons依赖
xml 复制代码
<!-- 引入自己定义的api通用包 -->
<dependency>
    <groupId>com.atguigu.cloud</groupId>
    <artifactId>cloud-api-commons</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

2.3.测试:

  • postman发送请求,进行接口测试:
相关推荐
短剑重铸之日3 天前
《SpringCloud实用版》Stream + RocketMQ 实现可靠消息 & 事务消息
后端·rocketmq·springcloud·消息中间件·事务消息
没有bug.的程序员5 天前
Spring Cloud Stream:消息驱动微服务的实战与 Kafka 集成终极指南
java·微服务·架构·kafka·stream·springcloud·消息驱动
没有bug.的程序员6 天前
Spring Cloud Gateway:API网关限流与熔断实战
java·开发语言·数据库·spring boot·gateway·api·springcloud
wfsm10 天前
nacos和openfeign
springcloud
无心水10 天前
【分布式利器:腾讯TSF】11、腾讯TSF微服务框架深度对比:全面解析TSF vs Spring Cloud vs Dubbo vs Service Mesh
分布式·spring cloud·微服务·dubbo·springcloud·service mesh·分布式利器
sunnyday042611 天前
Spring Cloud Alibaba Sentinel 流量控制与熔断降级实战指南
spring boot·sentinel·springcloud
悟空码字14 天前
Spring Cloud 集成 Nacos,全面的配置中心与服务发现解决方案
java·nacos·springcloud·编程技术·后端开发
坐不住的爱码20 天前
Bootstrap和application.yml
springcloud
悟空码字21 天前
Spring Cloud Gateway实战,从零搭建API网关,构建高性能微服务统一入口
java·gateway·springcloud·编程技术·后端开发
没有bug.的程序员22 天前
Service Mesh 与 Spring Cloud 共存方案:双体系治理、平滑迁移与风险控制实战指南
云原生·springcloud·流量治理·混合架构·servicemesh·微服务迁移·技术演进