I have a use case as described below.
I am defining a webclient.builder like below.
@Bean(“customBuilder)
public Webclient.Builder customBuilder(Webclient.Builder builder) {
return builder.headers().filters();
}
And when I try to run this, I am getting circular reference error because instead of getting spring managed builder, the above method is trying to get the same bean circularly as a first parameter. And I know, spring wont create a bean of its own if I create one myself. But the bean must be created for me here because I am using micrometer and only then it can populate traceparent in the header. I cannot use Webclient.builder() for the same reason. I cannot return Webclient either because this library will be provided as jar and other applications will customise this builder like adding baseurl, default headers, filters and build their webclient on thier own.
So, my ask is
- Is it possible to tell spring to create a builder and return it in the above method instead of circular referencing it.
- Worst case - populate traceparent myself without depending on internal methods. I can use tracer class here but I am not convinced to use it yet.
To make an
additive customization to all
instances, you can declare WebClientCustomizer beans and change the WebClient.Builder locally at the point of injection.
Finally, you can fall back to the original API and use
WebClient.create(). In that case, no auto-configuration or
is applied.