@FeignClient 接口上不允许使用@RequestMapping 注释

@RequestMapping annotation not allowed on @FeignClient interfaces

我遇到了麻烦!正如我一直在阅读的那样,它的发生是因为它不再被接受。但是我该如何解决呢? 这是我一直试图映射的代码。

@FeignClient(name = "product-service")
@RequestMapping("api/products/")
public interface ProductClient {

    @GetMapping("/{id}")
    ResponseEntity<Product> getProduct(@PathVariable("id") Long id);

    @GetMapping("/{id}/stock")
    ResponseEntity<Product> updateStockProduct(@PathVariable("id") Long id,@RequestParam(name = "quantity", required = true) Integer quantity);
}

提前感谢任何建议或解决方案!

您可以使用@FeignClientpath 属性来定义要添加到所有API 的路径前缀。文档是 here.

所以你的 Feign 客户端界面看起来像

@FeignClient(name = "product-service", path = "/api/products")
public interface ProductClient {

    @GetMapping("/{id}")
    ResponseEntity<Product> getProduct(@PathVariable("id") Long id);

    @GetMapping("/{id}/stock")
    ResponseEntity<Product> updateStockProduct(@PathVariable("id") Long id,@RequestParam(name = "quantity", required = true) Integer quantity);
}