FeignException:404

1,055 阅读1分钟

Q1: Resolved [feign.FeignException$NotFound: status 404 reading XXService#getXX

A:

1、首先是之前一次的问题,url默认找的是服务端,在@FeignClient上加入url指向本地启动的服务提供方

2、调用feign超时,可以在配置文件加上

feign:
  httpclient:
    connection-timeout: 30000

3、因为feign提供者在配置文件中增加了 context-path: /xxxx ,把它删掉

4、参数问题

5、路径问题,容易忽略的是被调用的服务中写了全局 @RequestMapping,调用的时候路径忘写了。

Feign注意事项

1\. @EnableFeignClients 默认扫描 xxxxApplication启动入口 所在包路径下的 @FeignClient bean,若无法扫描到, 可以在使用Feign调用外部模块的api时候,需要在引用服务中 xxxxApplication 中的   @EnableFeignClients(basePackages = "cn.tendyron.customer") 添加外部包需要扫描FeignClient的路径,否则无法注入bean 

2. @FeignClient 声明的类,使用 spring.application.name 作为 name配置 @FeignClient(name="xxxx"),如果想保留 context-path , 则需要配置 path 属性 ,如:@FeignClient(name="xxxx" , path="xxxx(context-path)") 

3. @FeignClient 接口对应的实现类,需要使用 @RestController注解 声明 

4. mapper注解不支持 : @GetMapping,@PostMapping , 参数要加 @RequestParam(“xxx”)

5. FeignClient 调用,实质是httpClient调用 ,若我们暴露的接口api,声明了对应的 http mapper 信息,在调用方调用时候,通过代理

Q2: java.lang.RuntimeException: com.netflix.client.ClientException: Load balancer does not have available

A:

ribbon:
    eureka:  
        enabled: true

参考

www.cnblogs.com/beiweixiaoh…

my.oschina.net/u/3245438/b…