语境
我有一个 spring boot (version 2.2.6.RELEASE) web 项目。
从这个 Web 应用程序(我称之为“APP1”)我想使用来自另一个 Web 应用程序的 PATCH 方法调用另一个 URI(我们称之为“APP2”)。
在我的 pom.xml 中,我有以下依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
下面是我如何调用其他 Web 应用程序的 PATCH 方法。
@FeignClient(name = "clientName", url = "base-uri")
public interface MyInterface{
@PatchMapping(value = "/target-uri")
void callClientMethod(Map<String, Object> args);
问题
我在互联网上寻找解决方案,并在我的 pom.xml 中添加了以下 snipet
<dependency>
<groupId>com.netflix.feign</groupId> <!-- Also tried io.github.openfeign -->
<artifactId>feign-httpclient</artifactId>
<version>8.18.0</version>
</dependency>
之后,APP2 的 PATCH 方法仍然被正确调用,但在 APP1 中我收到以下错误:
java.lang.NoSuchMethodError: feign.Response.create (ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)Lfeign/Response;
题
在此先感谢您的帮助 !
最佳答案
我遇到了同样的问题,花了很多时间来理解和解决这个问题。
首先,您需要了解的是,Feign 不支持从框中调用 PATCH http 方法!
如果您可以更改两个服务中的方法,请使用 PUT 进行更新而不是 PATCH ...
但是如果您与第三方实现集成,您应该添加一些配置:
1.添加支持PATCH http方法的依赖:
// https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp
compile group: 'io.github.openfeign', name: 'feign-okhttp', version: '10.2.0'
@Configuration public class FeignConfiguration { @Bean public OkHttpClient client() { return new OkHttpClient(); } }
@FeignClient(name = "someapi", url = "${client.someapi.url}") @Component @RequestMapping("/users") public interface SomeClient { @RequestMapping(value = "/{id}", method = RequestMethod.PATCH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) FeignUser update(@PathVariable("id") Long id, @RequestBody Map<String, Object> fields); }
希望它可以帮助某人。
关于spring-cloud-feign - Spring 云启动器-openfeign : Invalid HTTP method: PATCH executing PATCH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61641977/