使用 Feign 生成器时如何让 Spring sleuth 工作
How to get Spring sleuth to work when using Feign builder
我正在尝试让 spring 侦探通过我们的系统传播跟踪 ID。
在检查其他服务的日志时,我注意到正在生成新的 ID。
我认为这可能是因为我使用了 Feign 生成器,而我已经在使用 okHttpClient。
我遇到了以下情况:
https://github.com/spring-cloud/spring-cloud-sleuth/issues/594
我的 bean 设置如下:
@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 引导 2.1.2.RELEASE
org.springframework.cloud:spring-云侦探:2.1.0.RELEASE
在聊天 (https://chat.whosebug.com/rooms/188411/discussion-between-yk-47-and-marcin-grzejszczak) 中,我们分析了当前设置。它缺少 bean 定义,最重要的是 spring-cloud starter for open feign。
我正在尝试让 spring 侦探通过我们的系统传播跟踪 ID。
在检查其他服务的日志时,我注意到正在生成新的 ID。
我认为这可能是因为我使用了 Feign 生成器,而我已经在使用 okHttpClient。
我遇到了以下情况:
https://github.com/spring-cloud/spring-cloud-sleuth/issues/594
我的 bean 设置如下:
@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 引导 2.1.2.RELEASE
org.springframework.cloud:spring-云侦探:2.1.0.RELEASE
在聊天 (https://chat.whosebug.com/rooms/188411/discussion-between-yk-47-and-marcin-grzejszczak) 中,我们分析了当前设置。它缺少 bean 定义,最重要的是 spring-cloud starter for open feign。