Merge remote-tracking branch 'origin/main' into use-uri-template-attribute-in-metrics

This commit is contained in:
Olga Maciaszek-Sharma
2024-11-04 16:57:49 +01:00
5 changed files with 59 additions and 3 deletions

View File

@@ -253,6 +253,21 @@ public class MyClass {
The URI needs to use a virtual host name (that is, a service name, not a host name).
The `BlockingLoadBalancerClient` is used to create a full physical address.
In order to leverage additional capabilities that Spring Boot provides for `RestTemplateBuilder` (for example, observability support) you may want to use the autoconfigured
`RestTemplateBuilderConfigurer` while creating the `@LoadBalanced RestTemplateBuilder` beans:
[source,java,indent=0]
----
@Configuration
public class MyConfiguration {
@LoadBalanced
RestTemplateBuilder loadBalancedRestTemplateBuilder(RestTemplateBuilderConfigurer configurer) {
return configurer.configure(new RestTemplateBuilder());
}
}
----
IMPORTANT: To use it, add xref:spring-cloud-commons/loadbalancer.adoc#spring-cloud-loadbalancer-starter[Spring Cloud LoadBalancer starter] to your project.
[[multiple-resttemplate-builder-beans]]
@@ -333,6 +348,22 @@ public class MyClass {
The URI needs to use a virtual host name (that is, a service name, not a host name).
The `BlockingLoadBalancerClient` is used to create a full physical address.
In order to leverage additional capabilities that Spring Boot provides for `RestClient.Builder` (for example, observability support) you may want to use the autoconfigured
`RestClientBuilderConfigurer` while creating the `@LoadBalanced RestClient.Builder` beans:
[source,java,indent=0]
----
@Configuration
public class MyConfiguration {
@LoadBalanced
@Bean
RestClient.Builder restClientBuilder(RestClientBuilderConfigurer configurer) {
return configurer.configure(RestClient.builder());
}
}
----
IMPORTANT: To use it, add xref:spring-cloud-commons/loadbalancer.adoc#spring-cloud-loadbalancer-starter[Spring Cloud LoadBalancer starter] to your project.
[[multiple-restclient-objects]]
@@ -413,6 +444,24 @@ public class MyClass {
The URI needs to use a virtual host name (that is, a service name, not a host name).
The Spring Cloud LoadBalancer is used to create a full physical address.
In order to leverage additional capabilities that Spring Boot provides for `WebClient.Builder` (for example, observability support) you may want to use the autoconfigured
`WebClientCustomizer` beans while creating the `@LoadBalanced WebClient.Builder` beans:
[source,java,indent=0]
----
@Configuration
public class MyConfiguration {
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder(ObjectProvider<WebClientCustomizer> customizerProvider) {
WebClient.Builder builder = WebClient.builder();
customizerProvider.orderedStream().forEach((customizer) -> customizer.customize(builder));
return builder;
}
}
----
IMPORTANT: If you want to use a `@LoadBalanced WebClient.Builder`, you need to have a Spring Cloud LoadBalancer
implementation in the classpath. We recommend that you add the
xref:spring-cloud-commons/loadbalancer.adoc#spring-cloud-loadbalancer-starter[Spring Cloud LoadBalancer starter] to your project.

View File

@@ -80,6 +80,10 @@
<artifactId>httpclient5</artifactId>
</dependency>
</ignoredDependencies>
<ignoredResourcePatterns>
<ignoredResourcePattern>mockito-extensions/org.mockito.plugins.MockResolver</ignoredResourcePattern>
</ignoredResourcePatterns>
<checkTestClasspath>false</checkTestClasspath>
</configuration>
</plugin>
</plugins>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.cloud.configuration;
import java.util.Locale;
import java.util.Map;
import org.springframework.core.io.Resource;
@@ -143,7 +144,7 @@ public class TlsProperties {
String name = resource.getFilename();
int index = name.lastIndexOf('.');
return index < 0 ? "" : name.substring(index + 1).toLowerCase();
return index < 0 ? "" : name.substring(index + 1).toLowerCase(Locale.ROOT);
}
}

View File

@@ -50,7 +50,7 @@ public class LoadBalancedRestClientIntegrationTests {
RestClient client = restClientBuilder.build();
// Interceptors are not visible in RestClient
assertThatThrownBy(() -> client.get().uri("http://test-service").retrieve())
assertThatThrownBy(() -> client.get().uri("http://test-service").retrieve().toBodilessEntity())
.hasMessage("LoadBalancerInterceptor invoked.");
}

View File

@@ -22,4 +22,6 @@
<suppress files=".*AutoConfiguration.*" checks="HideUtilityClassConstructor"/>
<suppress files=".*AutoConfiguration.*" checks="FinalClass"/>
<suppress files=".*ReactiveDiscoveryClient.*" checks="JavadocVariable"/>
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/](java|java21)[\\/]" checks="RegexpSinglelineJava" id="toLowerCaseWithoutLocale"/>
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/](java|java21)[\\/]" checks="RegexpSinglelineJava" id="toUpperCaseWithoutLocale"/>
</suppressions>