使用Feign Builder时如何使Spring Sleuth工作

时间:2019-02-14 10:30:49

标签: spring spring-cloud spring-cloud-sleuth

我正在设法让弹簧更好地通过我们的系统传播跟踪ID。

在检查其他服务的日志时,我注意到正在生成新的ID。

我认为这可能是由于我使用了Feign构建器,而我已经在使用okHttpClient。

我遇到了以下问题:

https://github.com/spring-cloud/spring-cloud-sleuth/issues/594

How to implement Sleuth Tracing With Feign.Builder?

我的豆子设置如下:

@Configuration
@RequiredArgsConstructor
public class OkHttpConfig {

  private final Properties properties;

  @Bean
  public OkHttpClient okHttpClient() {
    return new Builder()
        .connectTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .readTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .writeTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .connectionPool(new ConnectionPool(properties.getHttpPoolSize(),
            properties.getHttpKeepAliveMillis(), TimeUnit.MILLISECONDS))
        .build();
  }
@Configuration
public class HttpClientConfiguration {

  @Autowired
  private Properties properties;

  @Autowired
  private Client client;

  @Bean
  public SomeClient SomeClient(Client client, ObjectMapper objectMapper {
    return feignClient(properties.getUrl(), SomeClient.class, client,
            objectMapper);
  }

  public static <T> T feignClient(String baseUrl, Class<T> clientClass,
      Client client, ObjectMapper objectMapper) {
    return Feign.builder()
        .client(client)
        .decoder(new JacksonDecoder(objectMapper))
        .encoder(new JacksonEncoder(objectMapper))
        .target(clientClass, baseUrl);
  }

我希望客户端被封装在跟踪实现中,但是我一直收到以下错误

Unsatisfied dependency expressed through field 'client'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'feign.Client' available: 
expected at least 1 bean which qualifies as autowire candidate.Dependency annotations:

使用以下版本:

Spring boot 2.1.2发布

org.springframework.cloud:spring-cloud-sleuth:2.1.0.RELEASE

1 个答案:

答案 0 :(得分:0)

在聊天(https://chat.stackoverflow.com/rooms/188411/discussion-between-yk-47-and-marcin-grzejszczak)中,我们分析了当前设置。它缺少bean的定义,最重要的是缺少开放式伪装的弹簧云启动器。