【全栈之路】微服务课程11_Feign之深入刨析

配置描述

  • Decoder feignDecoder: ResponseEntityDecoder (which wraps a SpringDecoder)
  • Encoder feignEncoder: SpringEncoder
  • Logger feignLogger: Slf4jLogger
  • Contract feignContract: SpringMvcContract
  • Feign.Builder feignBuilder: HystrixFeign.Builder
  • Client feignClient: if Ribbon is enabled it is a LoadBalancerFeignClient, * otherwise the default feign client is used.

代码配置【修改日志级别】

  • UserFeignClient.java
@FeignClient(name = "shop-provider-user", configuration = UserFeignConfig.class)
public interface UserFeignClient {
  @GetMapping("/users/{id}")
  User findById(@PathVariable("id") Long id);
}


/**
 * 该Feign Client的配置类,注意:
 * 1. 该类可以独立出去;
 * 2. 该类上也可添加@Configuration声明是一个配置类;
 * 配置类上也可添加@Configuration注解,声明这是一个配置类;
 * 但此时千万别将该放置在主应用程序上下文@ComponentScan所扫描的包中,
 * 否则,该配置将会被所有Feign Client共享,无法实现细粒度配置!
 *
 */
class UserFeignConfig {
  @Bean
  public Logger.Level logger() {
    return Logger.Level.FULL;
  }
}
  • application.yml

logging:
  level:
    # 配置日志级别
    com.dream.shop.feign.UserFeignClient: debug

属性配置【修改日志级别】

feign:
  client:
    config:
      feignName:
        connectTimeout: 5000  # 相当于Request.Options
        readTimeout: 5000     # 相当于Request.Options
        # 配置Feign的日志级别,相当于代码配置方式中的Logger
        loggerLevel: full
        # Feign的错误解码器,相当于代码配置方式中的ErrorDecoder
        errorDecoder: com.example.SimpleErrorDecoder
        # 配置重试,相当于代码配置方式中的Retryer
        retryer: com.example.SimpleRetryer
        # 配置拦截器,相当于代码配置方式中的RequestInterceptor
        requestInterceptors:
          - com.example.FooRequestInterceptor
          - com.example.BarRequestInterceptor
        decode404: false

例如

feign:
  client:
    config:
       shop-provider-user:
       loggerLevel: full
logging:
  level:
    # 配置日志级别
    com.dream.shop.feign.UserFeignClient: debug

测试输出

clipboard.png

你可能感兴趣的:(feign,springcloud,springboot)