Skip to content

Commit 2bce95f

Browse files
committed
Merge remote-tracking branch 'origin/4.1.x'
2 parents c9a92bf + 02fb33a commit 2bce95f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/modules/ROOT/pages/spring-cloud-commons/common-abstractions.adoc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ public class MyClass {
333333
The URI needs to use a virtual host name (that is, a service name, not a host name).
334334
The `BlockingLoadBalancerClient` is used to create a full physical address.
335335

336+
In order to leverage additional capabilities that Spring Boot provides for `RestClient.Builder` (for example, observability support) you may want to use the autoconfigured
337+
`RestClientBuilderConfigurer` while creating the `@LoadBalanced RestClient.Builder` beans:
338+
339+
[source,java,indent=0]
340+
----
341+
@Configuration
342+
public class MyConfiguration {
343+
344+
@LoadBalanced
345+
@Bean
346+
RestClient.Builder restClientBuilder(RestClientBuilderConfigurer configurer) {
347+
return configurer.configure(RestClient.builder());
348+
}
349+
}
350+
----
351+
336352
IMPORTANT: To use it, add xref:spring-cloud-commons/loadbalancer.adoc#spring-cloud-loadbalancer-starter[Spring Cloud LoadBalancer starter] to your project.
337353

338354
[[multiple-restclient-objects]]
@@ -413,6 +429,24 @@ public class MyClass {
413429
The URI needs to use a virtual host name (that is, a service name, not a host name).
414430
The Spring Cloud LoadBalancer is used to create a full physical address.
415431

432+
In order to leverage additional capabilities that Spring Boot provides for `WebClient.Builder` (for example, observability support) you may want to use the autoconfigured
433+
`WebClientCustomizer` beans while creating the `@LoadBalanced WebClient.Builder` beans:
434+
435+
[source,java,indent=0]
436+
----
437+
@Configuration
438+
public class MyConfiguration {
439+
440+
@Bean
441+
@LoadBalanced
442+
public WebClient.Builder loadBalancedWebClientBuilder(ObjectProvider<WebClientCustomizer> customizerProvider) {
443+
WebClient.Builder builder = WebClient.builder();
444+
customizerProvider.orderedStream().forEach((customizer) -> customizer.customize(builder));
445+
return builder;
446+
}
447+
}
448+
----
449+
416450
IMPORTANT: If you want to use a `@LoadBalanced WebClient.Builder`, you need to have a Spring Cloud LoadBalancer
417451
implementation in the classpath. We recommend that you add the
418452
xref:spring-cloud-commons/loadbalancer.adoc#spring-cloud-loadbalancer-starter[Spring Cloud LoadBalancer starter] to your project.

0 commit comments

Comments
 (0)