spring clould feign的坑

5 篇文章 0 订阅
1 篇文章 0 订阅

1. 学习用feign 时,一开始用@GetMapping 注解还可远程调用,没有问题

在当用@PathVariable传路径变量时,服务总报500.
百度发现 @PathVariable时,@RequestMapping不能用GetMapping直接替换,必须用对其value参数直接赋值才可用。正确如下:

@FeignClient(value = "test")
public interface IFeignTestService {
    // if PathVariable is used, it is forbidden to use @GetMapping to replace @RequestMapping;
    @RequestMapping(value = "/test/ribbon/test/{id}", method = RequestMethod.GET)
    public Object getTest(@PathVariable("id") String id);
}

2. 使用Feign 自定义配置时,为防止 @Configuration 被当成@Component加载,以致对所有@FeignClient 生效。

当用@ComponentScan 显示加载指定包,排除FeignConguration。
对@FeignClient的想要使用指定自定义配置的,可用conguration属性来指定

3. Feign 调用接口的日志

日志级别枚举类Logger.Level

NONE:不输出日志
BASIC:输出请求方法、URL、响应状态码、执行时间
HEADERS:基本信息以及请求和响应头
FULL:请求和响应的heads、body、metadata,建议使用这个级别

注:1. Feign的Level日志级别配置默认是:NONE,不要跟log日志混淆。 
   2. feign 日志的  log日志级别为DEBUG.

/**

  • if this configuration is scanned by the @ComponentScan, it will take effects on all the FeignClients.

  • Therefore, we use IgnoreComponentScan to avoid this configuration’s being scanned so that it can work

  • the specific Feign clients with annotation @FeignClient taking FeignConfiguration.class as the value of

  • its attribute configuration.
    */
    @Configuration
    @IgnoreComponentScan
    public class FeignConfiguration {

    /**

    • set feign log level basic, this need the debug level of
    • the logger(for example logback)to print the feign logs.
    • @return
      */
      @Bean
      Logger.Level feignLoggerLevel() {
      return Logger.Level.BASIC;
      }

}

参: Spring Cloud中Feign常见问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值