API 工件中技术依赖性的最佳实践

问题描述 投票:0回答:1

用例:我目前正在从事一个由多个微服务组成的项目。为了易于使用并且为了正确地对 API 进行版本控制,每个服务都为 API 提供了一个单独的 Maven 工件。然而,由于使用 Spring-Web、Jackson 等,API 中存在一些技术依赖性(Spring Web、Jackson、Reactor)。迟早,这可能会导致使用这些技术依赖项的冲突版本的其他微服务的开发团队出现问题。

package random.price.api

import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiResponses
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import reactor.core.publisher.Flux

@RequestMapping(value = ["/v1/price"], produces = [MediaType.APPLICATION_NDJSON_VALUE, MediaType.APPLICATION_JSON_VALUE])
interface PriceApi {

    @ApiOperation("Triggers a calculation")
    @ApiResponses(
        ApiResponse(code = 200, message = "Success/OK")
    )
    @PostMapping("")
    public ResponseEntity<Any> calculate()

    @ApiOperation("Gets all prices for a product")
    @ApiResponses(
        ApiResponse(code = 200, message = "Success/OK"),
        ApiResponse(code = 404, message = "NotFound - Product with id unknown")
    )
    @GetMapping("/{productId}")
    public ResponseEntity<Flux<Prices>> getPrices(@PathVariable("productId") String productId)

是否有任何最佳实践可以在不实现单独的 API 客户端和提供某种 SDK 的情况下避免这种情况?

java spring-boot api maven dependency-management
1个回答
0
投票

一个好主意是在父pom文件中使用通用依赖项! 接下来在模块中指定这些依赖项而不带版本:版本将从父 pom.xml 中获取。 架构师或首席开发人员应该控制项目中所有团队的版本更改和新依赖项的添加。

© www.soinside.com 2019 - 2024. All rights reserved.