Spring Cloud实战(五)-声明式接口模块

2023-11-12

接着上一篇 Spring Cloud实战(四)-配置中心 现在开始搭建api模块

一.声明式接口模块api

1.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">
    <parent>
        <artifactId>cloud-action</artifactId>
        <groupId>com.example</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>api</artifactId>

    <properties>
        <fastjson.version>1.2.80</fastjson.version>
    </properties>
    <dependencies>
        <!-- eureka客户端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- 配置中心客户端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- 消息总线 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>
        <!-- 配置文件自动刷新[https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_embedding_the_config_server] -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-monitor</artifactId>
        </dependency>
        <!-- 声明式调用框架-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <!-- 负载均衡器-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
        <!-- 服务容错框架-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
        </dependency>

        <!-- java校验 hibernate校验-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
    </dependencies>

</project>

2.业务功能定义

 UserServiceApi.java

package com.example.api.user;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 86188
 */
@RequestMapping(value = "/user")
public interface UserServiceApi {

    /**
     * 新增用户
     * @param phone 手机号
     * @return
     */
    @RequestMapping(value = "/createUserByPhone",method = RequestMethod.POST)
    User createUserByPhone(String phone);
    
}

OrderServiceApi.java

package com.example.api.order;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 86188
 */
@RequestMapping(value = "/order")
public interface OrderServiceApi {

    /**
     * 新增订单
     *
     * @param order 订单
     * @return
     */
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    ProductOrder createOrder(ProductOrder order);

}

RepositoryServiceApi.java

package com.example.api.repository;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 86188
 */
@RequestMapping(value = "/repository")
public interface RepositoryServiceApi {
    /**
     * 减库存
     *
     * @param productId 商品id
     * @param num       数量
     * @return
     */
    @RequestMapping(value = "/reduceProduct",method = RequestMethod.PUT)
    Boolean reduceProduct(String productId, int num);
}

PayServiceApi.java

package com.example.api.pay;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author 86188
 */
@RequestMapping(value = "/pay")
public interface PayServiceApi {
    /**
     * 创建支付订单
     *
     * @return
     */
    @RequestMapping(value = "/createPayOrder",method = RequestMethod.POST)
    PayOrder createPayOrder();
}

3.说明

这个模块非常简单,主要用于其他业务模块接口声明,可以把一些公共依赖放在这里,或者单独再建一个commons模块.

好了,这个模块到这里就先结束了,后面会逐步实现具体业务作为服务的提供者,预计使用manage-server服务作为消费者,将会使用openfeign实现声明式调用.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Cloud实战(五)-声明式接口模块 的相关文章

随机推荐

  • Windows 下 T-Kernel QEMU模拟器使用

    google了一下 没有找到T Kernel QEMU模拟器使用介绍的内容 只有T Kernel 自己的文档 那就简单的介绍一下 1 下载对应的T Kernel代码包 参考以前的文档 http blog csdn net robertson
  • Python:用指定的字拼成这个字本身

    字 字 字字字字字字字字字字字 字 字 字字字字字字字 字 字 字字字字字字字字字字字 字 字 字字字 符 符 符符符符 符符符符符 符 符 符 符 符 符 符 符 符符 符符符符符符符 符 符 符 符 符 符 符 符 符 符 符 符 符符
  • 逻辑设备名到物理设备名的映射实现

    为了实现设备的无关性 当应用程序请求使用I O设备时 应当用逻辑设备名 但系统值识别物理设备名 所以应在系统中需要配置一张逻辑设备表 用于将逻辑设备名映射到物理设备名 逻辑设备表LUT Logical Unit Table 在逻辑设备表中
  • 使用Anaconda创建python环境 & 常见错误

    目录 使用anaconda创建python环境 1 流程 1 使用 cmd 命令打开终端 2 执行 conda 命令进入conda环境 3 执行 conda creat name 环境名 python python版本 命令创建环境 2 常
  • 在vue中使用for循环有异步请求,每次都只获取到最后一个数据解决办法

    我预想是将标签数组 dynamicTags 使用for循环取出每个值 在遍历标签数组将值一一添加到数据库中 奈何for循环结束了 才去执行put请求 这就导致了只添了数组的最后一个值 原因是axios put请求是异步请求 解决方案 使用递
  • 分析整理文献的具体步骤_VOSviewer文献综述

    文献综述在科技论文和学位论文中占据着重要地位 是论文中的一个重要且不可或缺的部分 它是研究者在对某一学科 专业或专题的大量文献进行阅读 整理 筛选 分析 综合和提炼的基础上 用自己的语言综合叙述研究状况的情报研究成果 因此 文献综述的好坏直
  • 计算宽度_桥梁有效宽度计算,看看很有用!

    有效分布宽度实质上是剪力滞效应的反应 由于目前桥梁设计多用二维平面解析 故荷载的有效分布宽度仍需要计算 不过还有很多深层次问题还不能合理解答 有待进一步研究和探讨 各中间跨正弯矩段取该跨计算跨径的0 2倍 边跨正弯矩段取该跨计算跨径的0 2
  • 回溯法-装载问题

    子集树问题 和 子集树的0 1背包问题类似 但是没有考虑价格 include
  • 【Parallels Desktop】解决Sorry, This Application Cannot Be Run Under A Virtual Machine

    问题描述 解决步骤 Win R 或Cmd R 打开 运行 窗口 输入regedit并点击 确定 打开注册表编辑器 依次展开HKEY LOCAL MACHINE HARDWARE ACPI DSDT文件夹 鼠标右键点击PRLS 选择 重命名
  • Redis第二讲 Redis数据持久化AOF和RDB

    RDB快照 snapshot 在默认情况下 Redis 将内存数据库快照保存在名字为 dump rdb 的二进制文件中 你可以对 Redis 进行设置 让它在 N 秒内数据集至少有 M 个改动 这一条件被满足时 自动保存一次数据集 save
  • 【修仙境界】等级划分

    文章目录 一 下境界 1 炼气 一共13层 2 筑基 分初 中 后期和大圆满 3 结丹 分初 中 后期和大圆满 4 元婴 分初 中 后期和大圆满 5 化神 分初 中 后期和大圆满 二 中境界 1 炼虚 分初 中 后期和大圆满 2 合体 分初
  • C++ 编程出错的地方(考试选择题易错点)

    一 int IsSvn int n if n 7 0 return 1 要判断这个数能不能被7整除 你就只返回1吗 那岂不是只返回1 没有0的情况了 应该改为 int IsSvn int n if n 7 0 return 1 else r
  • 2021年电赛模块化程序总结

    文章目录 1 ADC0804 2 LCD1602 3 AD9854 1 ADC0804 集成A D转换器品种繁多 选用时应综合考虑各种因素选取集成芯片 一般逐次比较型A D转换器用的比较多 ADC0804就是这类单片集成A D转换器 ADC
  • 9、HTML:有序列表(ol),无序列表(ul),描述列表(dl、dt、dd)详解

    1 什么是列表 什么是列表 什么是有序列表 什么是无序列表 上面写的 3 句话就是一个列表 你懂得 2 有序列表 有序列表 英文叫做 ordered list 所以标签也是取这个词组的首字母 ol ol标签括起来的范围就是有序列表的范围 而
  • Win11怎么修改c盘用户名?

    Win11怎么修改c盘用户名 不知道的小伙伴们可以学起来了 谨慎操作 以下的方法提供给你 希望对你有所帮助 Win11更改C盘user用户名教程 一 开启Administrator权限并登入 搜索框搜索cmd 右击以管理员身份运行 出现cm
  • C++每日一问:C++ 内存管理——内存泄漏及处理

    2 内存泄漏 2 1 C 中动态内存分配引发问题的解决方案 假设我们要开发一个String类 它可以方便地处理字符串数据 我们可以在类中声明一个数组 考虑到有时候字符串极长 我们可以把数组大小设为200 但一般的情况下又不需要这么多的空间
  • 唯一分解定理(分解质因子)

    唯一分解定理 每个大于一的自然数均可写为质数的积 而且这些素因子按大小排列之后 写法只有一种方式 最简单的写法 include
  • matlab绘制正弦函数、幅度调制初步、Inner matrix dimensions must agree错误

    以sin 2 f t 表达式来绘制正弦图像 必须给定数值序列才能绘制出图像 t必须给定一个数值序列 然后计算出 y sin 函数值序列 以t为横轴 y为纵轴 就绘制出了图像 先给出f 4 在这里是有几个周期 采样率Fs 100 matlab
  • flask从入门到精通,知识讲解+代码演示 day1

    flask从入门到精通 知识讲解 代码演示 day1 文章目录 flask从入门到精通 知识讲解 代码演示 day1 一 flask是什么 二 使用步骤 1 创造flask项目 2 初入flask 3 flask代码初运行 4 flask从
  • Spring Cloud实战(五)-声明式接口模块

    接着上一篇 Spring Cloud实战 四 配置中心 现在开始搭建api模块 一 声明式接口模块api 1 pom xml