V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
cnzmz
V2EX  ›  问与答

Spring cloud 项目,如何进行接口版本管理比较好呢?

  •  
  •   cnzmz · Jul 27, 2023 · 1507 views
    This topic created in 1007 days ago, the information mentioned may be changed or developed.
    项目基本情况:
    Nacos 配置中心等
    Spring Gateway 网关。
    再有就是基础的系统服务 user system ,再有就是业务模块了。
    其实就是 SpringBalde 开源框架那一套。
    https://gitee.com/smallc/SpringBlade?_from=gitee_search

    在开发过程中发现某些接口会出现升级变更的情况,期望保留接口原来的接口,保留兼容性。

    目前搜索过程中确认到主流的做法有两种。
    1. URL 的形式 xxx/v1/user/list 这种。
    2. 传一个 Header 的形式,Accept: application/vnd.example+json;version=1.0
    或者自己定义一个 Header 传过去。

    目前搜索到的实现方案
    都是在业务模块中 定义注解、实现一个 RequestCondition<ApiVersionCondition> 这种形式
    类似 https://pdai.tech/md/spring/springboot/springboot-x-interface-version.html
    请问如果需要在多个业务模块中实现这个,怎么写这部分比较好呢。
    如果在每个模块中都写一遍感觉会比较重复。

    使用 Spring Gateway 网关能实现类似效果吗?这部分没有查到比较好的内容。
    2 replies    2023-07-27 16:20:15 +08:00
    Hurriance
        1
    Hurriance  
       Jul 27, 2023
    之前的项目用的是你说的主流做法的第一种 xxx/v1/user/list ,好处是很直观,尤其是需要根据 URL 调试的时候,缺点的话,不太优雅?看你的需求更侧重哪个吧。

    针对第一种的话,个人体验就是,同一个接口的不同版本尽量紧凑在一块,方便回溯对比。
    cnzmz
        2
    cnzmz  
    OP
       Jul 27, 2023
    @Hurriance 其实最主要的是后面的,如果是在业务模块配置的话,是不是业务模块都配置一遍呢,这样子就很麻烦。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1494 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.