首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用Feign builder时让Spring sleuth工作

如何在使用Feign builder时让Spring sleuth工作
EN

Stack Overflow用户
提问于 2019-02-14 18:30:49
回答 1查看 1.1K关注 0票数 1

我在试着让spring slueth在我们的系统中传播追踪ids。

在检查另一个服务的日志时,我注意到生成了新的Ids。

我想这可能是因为我使用了一个伪装的构建器,而我已经在使用okHttpClient了。

我遇到了以下内容:

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

How to implement Sleuth Tracing With Feign.Builder?

我的bean设置如下:

代码语言:javascript
复制
@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();
  }
代码语言:javascript
复制
@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);
  }

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

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-14 22:54:26

在聊天(https://chat.stackoverflow.com/rooms/188411/discussion-between-yk-47-and-marcin-grzejszczak)中,我们已经分析了当前的设置。它缺少bean定义,最重要的是缺少open feign的spring-cloud starter。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54688265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档