openfeign使用踩坑记录

1.报ClassNotFound   com.netflix.config.CachedDynamicIntProperty问题,原因是spring-cloud-starter-openfeign的spring-cloud-starter-netflix-archaius中没有CachedDynamicIntProperty这个类。 引入archaius-core的核心包即可,注意报错这里的com.google.common.collect.FluentIterable.append(Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable; but it does not exist 所以需要排除guava

<dependency>
      <groupId>com.netflix.archaius</groupId>
      <artifactId>archaius-core</artifactId>
      <version>0.7.6</version>
       <exclusions>
            <exclusion>
                 <groupId>com.google.guava</groupId>
                 <artifactId>guava</artifactId>
            </exclusion>
       </exclusions>
</dependency>    

2.feign.FeignException: status 405 reading FeignClient#getXXX(Long),405错误为请求方式不一致,明明定义的是GET请求,结果在发起service to service call时,被转换成了POST请求。原因是OpenFeign在构造请求时需要足够多的@RequestMapping/@RequestParam/@PathVariable/@RequestHeader等来构造http请求。通过阅读自己定义的FeignClient可以发现,GET请求中的参数定义缺少注解@RequestParam,故而报错。所以当使用feign传参数的时候,需要加上@RequestParam注解,否则对方服务无法识别参数。

原文地址:https://www.cnblogs.com/coderxiaobai/p/14760964.html