【问题标题】:How to get Patch rest method to work with Feign client如何让补丁休息方法与 Feign 客户端一起使用
【发布时间】:2020-09-07 03:35:32
【问题描述】:

试图让 Patch 与我的假客户一起工作。我已经添加了

io.github.openfeign:feign-httpclient:jar:10.2.3

到类路径,但在尝试进行 Patch 调用时仍然出现异常

无效的 HTTP 方法:PATCH 正在执行 PATCH...

Feign 客户端方法是这样的

@PatchMapping("/devices")
AppDevice patchDevice(@RequestHeader(AUTHORIZATION) String apiKey, AppDevice device);

怀疑这很重要,但我在我的 pom 中使用了带有以下内容的 spring boot

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Greenwich.SR3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
...

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-httpclient</artifactId>
    </dependency>

...

【问题讨论】:

    标签: spring spring-boot rest feign openfeign


    【解决方案1】:

    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-httpclient</artifactId>
    </dependency>
    

    这种依赖对我没有帮助。
    Feign 客户端不支持 PATCH 方法调用,为了解决这个问题你应该使用其他依赖:

    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-okhttp</artifactId>
        <version>10.2.0</version>
    </dependency>
    

    我在此处使用 gradle 依赖项和示例配置编写的更多详细信息: https://stackoverflow.com/a/63580015/8999575

    【讨论】:

    • 除了第一个依赖之外,它是否可以替代添加一个依赖项?
    猜你喜欢
    • 2020-01-23
    • 1970-01-01
    • 2018-06-21
    • 2016-10-28
    • 2011-01-03
    • 2016-05-17
    • 2022-01-08
    • 2017-09-10
    • 2019-01-25
    相关资源
    最近更新 更多