diff --git a/2.1.x/multi/multi__spring_cloud_commons_common_abstractions.html b/2.1.x/multi/multi__spring_cloud_commons_common_abstractions.html index 045022dc..20bba743 100644 --- a/2.1.x/multi/multi__spring_cloud_commons_common_abstractions.html +++ b/2.1.x/multi/multi__spring_cloud_commons_common_abstractions.html @@ -151,7 +151,7 @@ you would like to use for a given service, as shown in the following example:

2.5 Multiple RestTemplate objects

If you want a RestTemplate that is not load-balanced, create a RestTemplate bean and inject it. -To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:\

@Configuration
+To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:

@Configuration
 public class MyConfiguration {
 
     @LoadBalanced
@@ -168,8 +168,8 @@ To access the load-balanced RestTemplate, use the <
 }
 
 public class MyClass {
-    @Autowired
-    private RestTemplate restTemplate;
+@Autowired
+private RestTemplate restTemplate;
 
     @Autowired
     @LoadBalanced
@@ -182,7 +182,41 @@ To access the load-balanced RestTemplate, use the <
     public String doStuff() {
         return restTemplate.getForObject("https://example.com", String.class);
     }
-}
[Important]Important

Notice the use of the @Primary annotation on the plain RestTemplate declaration in the preceding example to disambiguate the unqualified @Autowired injection.

[Tip]Tip

If you see errors such as java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89, try injecting RestOperations or setting spring.aop.proxyTargetClass=true.

2.6 Spring WebFlux WebClient as a Load Balancer Client

2.6.1 Spring WebFlux WebClient with Reactive Load Balancer

WebClient can be configured to use the ReactiveLoadBalancer. +}

[Important]Important

Notice the use of the @Primary annotation on the plain RestTemplate declaration in the preceding example to disambiguate the unqualified @Autowired injection.

[Tip]Tip

If you see errors such as java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89, try injecting RestOperations or setting spring.aop.proxyTargetClass=true.

2.6 Multiple WebClient Objects

If you want a WebClient that is not load-balanced, create a WebClient bean and inject it. +To access the load-balanced WebClient, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:

@Configuration
+public class MyConfiguration {
+
+    @LoadBalanced
+    @Bean
+    WebClient.Builder loadBalanced() {
+        return WebClient.builder();
+    }
+
+    @Primary
+    @Bean
+    WebClient.Builder webClient() {
+        return WebClient.builder();
+    }
+}
+
+public class MyClass {
+    @Autowired
+    private WebClient.Builder webClientBuilder;
+
+    @Autowired
+    @LoadBalanced
+    private WebClient.Builder loadBalanced;
+
+    public Mono<String> doOtherStuff() {
+        return loadBalanced.build().get().uri("http://stores/stores")
+        				.retrieve().bodyToMono(String.class);
+    }
+
+    public Mono<String> doStuff() {
+        return webClientBuilder.build().get().uri("http://example.com")
+        				.retrieve().bodyToMono(String.class);
+    }
+}

2.7 Spring WebFlux WebClient as a Load Balancer Client

2.7.1 Spring WebFlux WebClient with Reactive Load Balancer

WebClient can be configured to use the ReactiveLoadBalancer. If you add org.springframework.cloud:spring-cloud-loadbalancer to your project, ReactorLoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath. The following example shows how to configure a WebClient to use reactive load balancer under the hood:

public class MyClass {
@@ -199,7 +233,7 @@ The following example shows how to configure a WebClientclass);
     }
 }

The URI needs to use a virtual host name (that is, a service name, not a host name). -The ReactorLoadBalancerClient is used to create a full physical address.

2.6.2 Spring WebFlux WebClient with non-reactive Load Balancer Client

If you you don’t have org.springframework.cloud:spring-cloud-loadbalancer in your project, +The ReactorLoadBalancerClient is used to create a full physical address.

2.7.2 Spring WebFlux WebClient with non-reactive Load Balancer Client

If you you don’t have org.springframework.cloud:spring-cloud-loadbalancer in your project, but you do have spring-cloud-starter-netflix-ribbon, you can still use WebClient with LoadBalancerClient. LoadBalancerExchangeFilterFunction will be auto-configured if spring-webflux is on the classpath. Please note, however, that this is uses a non-reactive client under the hood. @@ -217,10 +251,9 @@ The following example shows how to configure a WebClientclass); } }

The URI needs to use a virtual host name (that is, a service name, not a host name). -The LoadBalancerClient is used to create a full physical address.

WARN: -This approach is now deprecated. -We suggest you use WebFlux with reactive Load-Balancer -instead.

2.6.3 Passing your own Load-Balancer Client configuration

You can also use the @LoadBalancerClient annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:

@Configuration
+The LoadBalancerClient is used to create a full physical address.

WARN: This approach is now deprecated. +We suggest you use WebFlux with reactive Load-Balancer +instead.

2.7.3 Passing your own Load-Balancer Client configuration

You can also use the @LoadBalancerClient annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:

@Configuration
 @LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class)
 public class MyConfiguration {
 
@@ -238,7 +271,7 @@ instead.

public WebClient.Builder loadBalancedWebClientBuilder() { return WebClient.builder(); } -}

2.7 Ignore Network Interfaces

Sometimes, it is useful to ignore certain named network interfaces so that they can be excluded from Service Discovery registration (for example, when running in a Docker container). +}

2.8 Ignore Network Interfaces

Sometimes, it is useful to ignore certain named network interfaces so that they can be excluded from Service Discovery registration (for example, when running in a Docker container). A list of regular expressions can be set to cause the desired network interfaces to be ignored. The following configuration ignores the docker0 interface and all interfaces that start with veth:

application.yml. 

spring:
@@ -258,16 +291,16 @@ The following configuration ignores the docker0 int
 .application.yml

spring:
   cloud:
     inetutils:
-      useOnlySiteLocalInterfaces: true

See Inet4Address.html.isSiteLocalAddress() for more details about what constitutes a site-local address.

2.8 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) and OK HTTP clients (OkHttpClientFactory). + useOnlySiteLocalInterfaces: true

See Inet4Address.html.isSiteLocalAddress() for more details about what constitutes a site-local address.

2.9 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) and OK HTTP clients (OkHttpClientFactory). The OkHttpClientFactory bean is created only if the OK HTTP jar is on the classpath. In addition, Spring Cloud Commons provides beans for creating the connection managers used by both clients: ApacheHttpClientConnectionManagerFactory for the Apache HTTP client and OkHttpClientConnectionPoolFactory for the OK HTTP client. If you would like to customize how the HTTP clients are created in downstream projects, you can provide your own implementation of these beans. In addition, if you provide a bean of type HttpClientBuilder or OkHttpClient.Builder, the default factories use these builders as the basis for the builders returned to downstream projects. -You can also disable the creation of these beans by setting spring.cloud.httpclientfactories.apache.enabled or spring.cloud.httpclientfactories.ok.enabled to false.

2.9 Enabled Features

Spring Cloud Commons provides a /features actuator endpoint. +You can also disable the creation of these beans by setting spring.cloud.httpclientfactories.apache.enabled or spring.cloud.httpclientfactories.ok.enabled to false.

2.10 Enabled Features

Spring Cloud Commons provides a /features actuator endpoint. This endpoint returns features available on the classpath and whether they are enabled. -The information returned includes the feature type, name, version, and vendor.

2.9.1 Feature types

There are two types of 'features': abstract and named.

Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as DiscoveryClient, LoadBalancerClient, or LockService. +The information returned includes the feature type, name, version, and vendor.

2.10.1 Feature types

There are two types of 'features': abstract and named.

Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as DiscoveryClient, LoadBalancerClient, or LockService. The abstract class or interface is used to find a bean of that type in the context. -The version displayed is bean.getClass().getPackage().getImplementationVersion().

Named features are features that do not have a particular class they implement, such as "Circuit Breaker", "API Gateway", "Spring Cloud Bus", and others. These features require a name and a bean type.

2.9.2 Declaring features

Any module can declare any number of HasFeature beans, as shown in the following examples:

@Bean
+The version displayed is bean.getClass().getPackage().getImplementationVersion().

Named features are features that do not have a particular class they implement, such as "Circuit Breaker", "API Gateway", "Spring Cloud Bus", and others. These features require a name and a bean type.

2.10.2 Declaring features

Any module can declare any number of HasFeature beans, as shown in the following examples:

@Bean
 public HasFeatures commonsFeatures() {
   return HasFeatures.abstractFeatures(DiscoveryClient.class, LoadBalancerClient.class);
 }
@@ -286,7 +319,7 @@ HasFeatures localFeatures() {
       .namedFeature(new NamedFeature("Bar Feature", Bar.class))
       .abstractFeature(Baz.class)
       .build();
-}

Each of these beans should go in an appropriately guarded @Configuration.

2.10 Spring Cloud Compatibility Verification

Due to the fact that some users have problem with setting up Spring Cloud application, we’ve decided +}

Each of these beans should go in an appropriately guarded @Configuration.

2.11 Spring Cloud Compatibility Verification

Due to the fact that some users have problem with setting up Spring Cloud application, we’ve decided to add a compatibility verification mechanism. It will break if your current setup is not compatible with Spring Cloud requirements, together with a report, showing what exactly went wrong.

At the moment we verify which version of Spring Boot is added to your classpath.

Example of a report

***************************
 APPLICATION FAILED TO START
diff --git a/2.1.x/multi/multi_spring-cloud-commons.html b/2.1.x/multi/multi_spring-cloud-commons.html
index 7f6241a4..b2144b68 100644
--- a/2.1.x/multi/multi_spring-cloud-commons.html
+++ b/2.1.x/multi/multi_spring-cloud-commons.html
@@ -1,3 +1,3 @@
 
       
-   Cloud Native Applications
\ No newline at end of file
+   Cloud Native Applications
\ No newline at end of file
diff --git a/2.1.x/single/spring-cloud-commons.html b/2.1.x/single/spring-cloud-commons.html
index 1758d824..0685611c 100644
--- a/2.1.x/single/spring-cloud-commons.html
+++ b/2.1.x/single/spring-cloud-commons.html
@@ -1,6 +1,6 @@
 
       
-   Cloud Native Applications

Cloud Native Applications


Cloud Native is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development. + Cloud Native Applications

Cloud Native Applications


Cloud Native is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development. A related discipline is that of building 12-factor Applications, in which development practices are aligned with delivery and operations goals — for instance, by using declarative programming and management and monitoring. Spring Cloud facilitates these styles of development in a number of specific ways. The starting point is a set of features to which all components in a distributed system need easy access.

Many of those features are covered by Spring Boot, on which Spring Cloud builds. Some more features are delivered by Spring Cloud as two libraries: Spring Cloud Context and Spring Cloud Commons. @@ -250,7 +250,7 @@ you would like to use for a given service, as shown in the following example:

2.5 Multiple RestTemplate objects

If you want a RestTemplate that is not load-balanced, create a RestTemplate bean and inject it. -To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:\

@Configuration
+To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:

@Configuration
 public class MyConfiguration {
 
     @LoadBalanced
@@ -267,8 +267,8 @@ To access the load-balanced RestTemplate, use the <
 }
 
 public class MyClass {
-    @Autowired
-    private RestTemplate restTemplate;
+@Autowired
+private RestTemplate restTemplate;
 
     @Autowired
     @LoadBalanced
@@ -281,7 +281,41 @@ To access the load-balanced RestTemplate, use the <
     public String doStuff() {
         return restTemplate.getForObject("https://example.com", String.class);
     }
-}
[Important]Important

Notice the use of the @Primary annotation on the plain RestTemplate declaration in the preceding example to disambiguate the unqualified @Autowired injection.

[Tip]Tip

If you see errors such as java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89, try injecting RestOperations or setting spring.aop.proxyTargetClass=true.

2.6 Spring WebFlux WebClient as a Load Balancer Client

2.6.1 Spring WebFlux WebClient with Reactive Load Balancer

WebClient can be configured to use the ReactiveLoadBalancer. +}

[Important]Important

Notice the use of the @Primary annotation on the plain RestTemplate declaration in the preceding example to disambiguate the unqualified @Autowired injection.

[Tip]Tip

If you see errors such as java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89, try injecting RestOperations or setting spring.aop.proxyTargetClass=true.

2.6 Multiple WebClient Objects

If you want a WebClient that is not load-balanced, create a WebClient bean and inject it. +To access the load-balanced WebClient, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:

@Configuration
+public class MyConfiguration {
+
+    @LoadBalanced
+    @Bean
+    WebClient.Builder loadBalanced() {
+        return WebClient.builder();
+    }
+
+    @Primary
+    @Bean
+    WebClient.Builder webClient() {
+        return WebClient.builder();
+    }
+}
+
+public class MyClass {
+    @Autowired
+    private WebClient.Builder webClientBuilder;
+
+    @Autowired
+    @LoadBalanced
+    private WebClient.Builder loadBalanced;
+
+    public Mono<String> doOtherStuff() {
+        return loadBalanced.build().get().uri("http://stores/stores")
+        				.retrieve().bodyToMono(String.class);
+    }
+
+    public Mono<String> doStuff() {
+        return webClientBuilder.build().get().uri("http://example.com")
+        				.retrieve().bodyToMono(String.class);
+    }
+}

2.7 Spring WebFlux WebClient as a Load Balancer Client

2.7.1 Spring WebFlux WebClient with Reactive Load Balancer

WebClient can be configured to use the ReactiveLoadBalancer. If you add org.springframework.cloud:spring-cloud-loadbalancer to your project, ReactorLoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath. The following example shows how to configure a WebClient to use reactive load balancer under the hood:

public class MyClass {
@@ -298,7 +332,7 @@ The following example shows how to configure a WebClientclass);
     }
 }

The URI needs to use a virtual host name (that is, a service name, not a host name). -The ReactorLoadBalancerClient is used to create a full physical address.

2.6.2 Spring WebFlux WebClient with non-reactive Load Balancer Client

If you you don’t have org.springframework.cloud:spring-cloud-loadbalancer in your project, +The ReactorLoadBalancerClient is used to create a full physical address.

2.7.2 Spring WebFlux WebClient with non-reactive Load Balancer Client

If you you don’t have org.springframework.cloud:spring-cloud-loadbalancer in your project, but you do have spring-cloud-starter-netflix-ribbon, you can still use WebClient with LoadBalancerClient. LoadBalancerExchangeFilterFunction will be auto-configured if spring-webflux is on the classpath. Please note, however, that this is uses a non-reactive client under the hood. @@ -316,10 +350,9 @@ The following example shows how to configure a WebClientclass); } }

The URI needs to use a virtual host name (that is, a service name, not a host name). -The LoadBalancerClient is used to create a full physical address.

WARN: -This approach is now deprecated. -We suggest you use WebFlux with reactive Load-Balancer -instead.

2.6.3 Passing your own Load-Balancer Client configuration

You can also use the @LoadBalancerClient annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:

@Configuration
+The LoadBalancerClient is used to create a full physical address.

WARN: This approach is now deprecated. +We suggest you use WebFlux with reactive Load-Balancer +instead.

2.7.3 Passing your own Load-Balancer Client configuration

You can also use the @LoadBalancerClient annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:

@Configuration
 @LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class)
 public class MyConfiguration {
 
@@ -337,7 +370,7 @@ instead.

public WebClient.Builder loadBalancedWebClientBuilder() { return WebClient.builder(); } -}

2.7 Ignore Network Interfaces

Sometimes, it is useful to ignore certain named network interfaces so that they can be excluded from Service Discovery registration (for example, when running in a Docker container). +}

2.8 Ignore Network Interfaces

Sometimes, it is useful to ignore certain named network interfaces so that they can be excluded from Service Discovery registration (for example, when running in a Docker container). A list of regular expressions can be set to cause the desired network interfaces to be ignored. The following configuration ignores the docker0 interface and all interfaces that start with veth:

application.yml. 

spring:
@@ -357,16 +390,16 @@ The following configuration ignores the docker0 int
 .application.yml

spring:
   cloud:
     inetutils:
-      useOnlySiteLocalInterfaces: true

See Inet4Address.html.isSiteLocalAddress() for more details about what constitutes a site-local address.

2.8 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) and OK HTTP clients (OkHttpClientFactory). + useOnlySiteLocalInterfaces: true

See Inet4Address.html.isSiteLocalAddress() for more details about what constitutes a site-local address.

2.9 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) and OK HTTP clients (OkHttpClientFactory). The OkHttpClientFactory bean is created only if the OK HTTP jar is on the classpath. In addition, Spring Cloud Commons provides beans for creating the connection managers used by both clients: ApacheHttpClientConnectionManagerFactory for the Apache HTTP client and OkHttpClientConnectionPoolFactory for the OK HTTP client. If you would like to customize how the HTTP clients are created in downstream projects, you can provide your own implementation of these beans. In addition, if you provide a bean of type HttpClientBuilder or OkHttpClient.Builder, the default factories use these builders as the basis for the builders returned to downstream projects. -You can also disable the creation of these beans by setting spring.cloud.httpclientfactories.apache.enabled or spring.cloud.httpclientfactories.ok.enabled to false.

2.9 Enabled Features

Spring Cloud Commons provides a /features actuator endpoint. +You can also disable the creation of these beans by setting spring.cloud.httpclientfactories.apache.enabled or spring.cloud.httpclientfactories.ok.enabled to false.

2.10 Enabled Features

Spring Cloud Commons provides a /features actuator endpoint. This endpoint returns features available on the classpath and whether they are enabled. -The information returned includes the feature type, name, version, and vendor.

2.9.1 Feature types

There are two types of 'features': abstract and named.

Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as DiscoveryClient, LoadBalancerClient, or LockService. +The information returned includes the feature type, name, version, and vendor.

2.10.1 Feature types

There are two types of 'features': abstract and named.

Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as DiscoveryClient, LoadBalancerClient, or LockService. The abstract class or interface is used to find a bean of that type in the context. -The version displayed is bean.getClass().getPackage().getImplementationVersion().

Named features are features that do not have a particular class they implement, such as "Circuit Breaker", "API Gateway", "Spring Cloud Bus", and others. These features require a name and a bean type.

2.9.2 Declaring features

Any module can declare any number of HasFeature beans, as shown in the following examples:

@Bean
+The version displayed is bean.getClass().getPackage().getImplementationVersion().

Named features are features that do not have a particular class they implement, such as "Circuit Breaker", "API Gateway", "Spring Cloud Bus", and others. These features require a name and a bean type.

2.10.2 Declaring features

Any module can declare any number of HasFeature beans, as shown in the following examples:

@Bean
 public HasFeatures commonsFeatures() {
   return HasFeatures.abstractFeatures(DiscoveryClient.class, LoadBalancerClient.class);
 }
@@ -385,7 +418,7 @@ HasFeatures localFeatures() {
       .namedFeature(new NamedFeature("Bar Feature", Bar.class))
       .abstractFeature(Baz.class)
       .build();
-}

Each of these beans should go in an appropriately guarded @Configuration.

2.10 Spring Cloud Compatibility Verification

Due to the fact that some users have problem with setting up Spring Cloud application, we’ve decided +}

Each of these beans should go in an appropriately guarded @Configuration.

2.11 Spring Cloud Compatibility Verification

Due to the fact that some users have problem with setting up Spring Cloud application, we’ve decided to add a compatibility verification mechanism. It will break if your current setup is not compatible with Spring Cloud requirements, together with a report, showing what exactly went wrong.

At the moment we verify which version of Spring Boot is added to your classpath.

Example of a report

***************************
 APPLICATION FAILED TO START
diff --git a/2.1.x/spring-cloud-commons.xml b/2.1.x/spring-cloud-commons.xml
index 170650c2..01dc61ae 100644
--- a/2.1.x/spring-cloud-commons.xml
+++ b/2.1.x/spring-cloud-commons.xml
@@ -507,7 +507,7 @@ public class MyConfiguration {
 
Multiple RestTemplate objects If you want a RestTemplate that is not load-balanced, create a RestTemplate bean and inject it. -To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example:\ +To access the load-balanced RestTemplate, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example: @Configuration public class MyConfiguration { @@ -525,8 +525,8 @@ public class MyConfiguration { } public class MyClass { - @Autowired - private RestTemplate restTemplate; +@Autowired +private RestTemplate restTemplate; @Autowired @LoadBalanced @@ -547,6 +547,45 @@ public class MyClass { If you see errors such as java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89, try injecting RestOperations or setting spring.aop.proxyTargetClass=true.
+
+Multiple WebClient Objects +If you want a WebClient that is not load-balanced, create a WebClient bean and inject it. +To access the load-balanced WebClient, use the @LoadBalanced qualifier when you create your @Bean, as shown in the following example: +@Configuration +public class MyConfiguration { + + @LoadBalanced + @Bean + WebClient.Builder loadBalanced() { + return WebClient.builder(); + } + + @Primary + @Bean + WebClient.Builder webClient() { + return WebClient.builder(); + } +} + +public class MyClass { + @Autowired + private WebClient.Builder webClientBuilder; + + @Autowired + @LoadBalanced + private WebClient.Builder loadBalanced; + + public Mono<String> doOtherStuff() { + return loadBalanced.build().get().uri("http://stores/stores") + .retrieve().bodyToMono(String.class); + } + + public Mono<String> doStuff() { + return webClientBuilder.build().get().uri("http://example.com") + .retrieve().bodyToMono(String.class); + } +} +
Spring WebFlux WebClient as a Load Balancer Client
@@ -595,8 +634,7 @@ The following example shows how to configure a WebClient to u } The URI needs to use a virtual host name (that is, a service name, not a host name). The LoadBalancerClient is used to create a full physical address. -WARN: -This approach is now deprecated. +WARN: This approach is now deprecated. We suggest you use WebFlux with reactive Load-Balancer instead.