I have few microservices in my project, as is standard i am using discovery server and track distributed tracing using zipkin :
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
As per documentation
If you create the WebClient or the RestTemplate without using the auto-configured builders, automatic trace propagation won’t work!
so i need to use autoconfigured WebClient.Builder
, however since i have multiple instance of microservices, i need to use LoadBalanced
on webclient.
The autoconfigured builder does not contains @LoadBalanced
annotation (WebClientAutoConfiguration.class):
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
public WebClient.Builder webClientBuilder(ObjectProvider<WebClientCustomizer> customizerProvider) {
WebClient.Builder builder = WebClient.builder();
customizerProvider.orderedStream().forEach((customizer) -> {
customizer.customize(builder);
});
return builder;
}
So i used:
@Bean
@LoadBalanced
public WebClient.Builder webClient(WebClient.Builder builder) {
return builder;
}
However this throws:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐ | webClient defined in class path resource [...//WebClientConfig.class]
└─────┘
I could probably make some wrapper/adapter for WebClient/WebClient.Builder to fix this, however that seems like overkill for such problem ( since it contains lots of methods )
What could be causing this? I am using
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/>
</parent>
for parent of my parent pom. Thanks for answers.