I was able to solve my problem by adding RestClient.Builder as a parameter of the bean created in the class RestClientConfig.
So for valid handling Trace ID by RestClient in Spring Boot 3 application the class RestClientConfig should be configured in following way:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import com.example.clients.BeClient;
@Configuration
public class RestClientConfig {
@Value("${api.url}")
private String apiUrl;
@Bean
public BeClient beClient(RestClient.Builder restClientBuilder) {
RestClient restClient = restClientBuilder
.baseUrl(apiUrl)
.build();
var restClientAdapter = RestClientAdapter.create(restClient);
var httpServiceProxyFactory = HttpServiceProxyFactory.builderFor(restClientAdapter).build();
return httpServiceProxyFactory.createClient(BeClient.class);
}
}
Working source code you can find here: https://github.com/wisniewskikr/chrisblog-it-cloud/tree/main/spring-cloud/observability/springcloud-springboot3-observability-grafana-stack-restclient