Feign调用第三方接口的错误:Method addUser not annotated with HTTP method type (ex. GET, POST)

1.检查降级方法的@PathVariable,其中的(“id”)不能省掉

@RequestMapping(value = "/add/{id}", method = RequestMethod.POST)
public String addUser(@PathVariable("id") String id);

2.检查Fegin配置文件配置文件有没有以下代码,发果有则删除掉,该代码是确定fegin的契约为@RequestLine, 删除后就会使用@RequestMapping 契约

   @Bean
   public Contract feignContract() {
        return new feign.Contract.Default();
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Feign是一个基于Java的声明式HTTP客户端,用于简化调用第三方接口的开发。使用Feign可以让我们像调用本地方法一样调用远程接口。 要使用Feign调用第三方接口,首先需要在项目中引入Feign的依赖。在Maven项目中,可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> ``` 接下来,在定义调用远程接口接口上添加`@FeignClient`注解,并指定要调用的远程服务的名称。例如: ```java @FeignClient(name = "third-party-service") public interface ThirdPartyServiceClient { @GetMapping("/api/some-resource") ResponseEntity<String> getSomeResource(); } ``` 在上述示例中,`ThirdPartyServiceClient`接口定义了一个`getSomeResource()`方法,用于调用第三方服务的`/api/some-resource`接口。 最后,在需要调用远程接口的地方注入`ThirdPartyServiceClient`接口,并使用该接口的方法进行调用。例如: ```java @RestController public class MyController { private final ThirdPartyServiceClient thirdPartyServiceClient; public MyController(ThirdPartyServiceClient thirdPartyServiceClient) { this.thirdPartyServiceClient = thirdPartyServiceClient; } @GetMapping("/my-endpoint") public ResponseEntity<String> myEndpoint() { return thirdPartyServiceClient.getSomeResource(); } } ``` 在上述示例中,`MyController`中的`myEndpoint()`方法通过调用`ThirdPartyServiceClient`接口的方法来获取第三方服务的资源。 需要注意的是,Feign还支持其他功能,如请求拦截器、熔断器等,可以根据具体需求进行配置和使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值