@ -19,8 +19,8 @@ properties to set the order of the <code class="literal">DiscoveryClient</code>
@@ -19,8 +19,8 @@ properties to set the order of the <code class="literal">DiscoveryClient</code>
implementations provided by Spring Cloud, among others <codeclass="literal">ConsulDiscoveryClient</code>, <codeclass="literal">EurekaDiscoveryClient</code> and
<codeclass="literal">ZookeeperDiscoveryClient</code>. In order to do it, you just need to set the
<codeclass="literal">spring.cloud.{clientIdentifier}.discovery.order</code> (or <codeclass="literal">eureka.client.order</code> for Eureka) property to the desired value.</p></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_serviceregistry"href="#_serviceregistry"></a>2.2 ServiceRegistry</h2></div></div></div><p>Commons now provides a <codeclass="literal">ServiceRegistry</code> interface that provides methods such as <codeclass="literal">register(Registration)</code> and <codeclass="literal">deregister(Registration)</code>, which let you provide custom registered services.
<codeclass="literal">Registration</code> is a marker interface.</p><p>The following example shows the <codeclass="literal">ServiceRegistry</code> in use:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
<codeclass="literal">Registration</code> is a marker interface.</p><p>The following example shows the <codeclass="literal">ServiceRegistry</code> in use:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -48,18 +48,18 @@ Using POST to the same endpoint with a JSON body changes the status of the curre
@@ -48,18 +48,18 @@ Using POST to the same endpoint with a JSON body changes the status of the curre
The JSON body has to include the <codeclass="literal">status</code> field with the preferred value.
Please see the documentation of the <codeclass="literal">ServiceRegistry</code> implementation you use for the allowed values when updating the status and the values returned for the status.
For instance, Eureka’s supported statuses are <codeclass="literal">UP</code>, <codeclass="literal">DOWN</code>, <codeclass="literal">OUT_OF_SERVICE</code>, and <codeclass="literal">UNKNOWN</code>.</p></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_spring_resttemplate_as_a_load_balancer_client"href="#_spring_resttemplate_as_a_load_balancer_client"></a>2.3 Spring RestTemplate as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">RestTemplate</code> can be automatically configured to use ribbon.
To create a load-balanced <codeclass="literal">RestTemplate</code>, create a <codeclass="literal">RestTemplate</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To create a load-balanced <codeclass="literal">RestTemplate</code>, create a <codeclass="literal">RestTemplate</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -70,18 +70,18 @@ To create a load-balanced <code class="literal">RestTemplate</code>, create a <c
@@ -70,18 +70,18 @@ To create a load-balanced <code class="literal">RestTemplate</code>, create a <c
Individual applications must create it.</p></td></tr></table></div><p>The URI needs to use a virtual host name (that is, a service name, not a host name).
The Ribbon client is used to create a full physical address.
See <aclass="link"href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java"target="_top">RibbonAutoConfiguration</a> for details of how the <codeclass="literal">RestTemplate</code> is set up.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_spring_webclient_as_a_load_balancer_client"href="#_spring_webclient_as_a_load_balancer_client"></a>2.4 Spring WebClient as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">WebClient</code> can be automatically configured to use the <codeclass="literal">LoadBalancerClient</code>.
To create a load-balanced <codeclass="literal">WebClient</code>, create a <codeclass="literal">WebClient.Builder</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To create a load-balanced <codeclass="literal">WebClient</code>, create a <codeclass="literal">WebClient.Builder</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -95,12 +95,12 @@ You can enable it by adding <a class="link" href="https://github.com/spring-proj
@@ -95,12 +95,12 @@ You can enable it by adding <a class="link" href="https://github.com/spring-proj
The load-balanced <codeclass="literal">RestTemplate</code> honors some of the Ribbon configuration values related to retrying failed requests.
You can use <codeclass="literal">client.ribbon.MaxAutoRetries</code>, <codeclass="literal">client.ribbon.MaxAutoRetriesNextServer</code>, and <codeclass="literal">client.ribbon.OkToRetryOnAllOperations</code> properties.
If you would like to disable the retry logic with Spring Retry on the classpath, you can set <codeclass="literal">spring.cloud.loadbalancer.retry.enabled=false</code>.
See the <aclass="link"href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties"target="_top">Ribbon documentation</a> for a description of what these properties do.</p><p>If you would like to implement a <codeclass="literal">BackOffPolicy</code> in your retries, you need to create a bean of type <codeclass="literal">LoadBalancedRetryFactory</code> and override the <codeclass="literal">createBackOffPolicy</code> method:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
See the <aclass="link"href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties"target="_top">Ribbon documentation</a> for a description of what these properties do.</p><p>If you would like to implement a <codeclass="literal">BackOffPolicy</code> in your retries, you need to create a bean of type <codeclass="literal">LoadBalancedRetryFactory</code> and override the <codeclass="literal">createBackOffPolicy</code> method:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -108,26 +108,26 @@ See the <a class="link" href="https://github.com/Netflix/ribbon/wiki/Getting-Sta
@@ -108,26 +108,26 @@ See the <a class="link" href="https://github.com/Netflix/ribbon/wiki/Getting-Sta
}
}</pre><divclass="note"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Note"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Note]"src="images/note.png"></td><thalign="left">Note</th></tr><tr><tdalign="left"valign="top"><p><codeclass="literal">client</code> in the preceding examples should be replaced with your Ribbon client’s name.</p></td></tr></table></div><p>If you want to add one or more <codeclass="literal">RetryListener</code> implementations to your retry functionality, you need to
create a bean of type <codeclass="literal">LoadBalancedRetryListenerFactory</code> and return the <codeclass="literal">RetryListener</code> array
you would like to use for a given service, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
you would like to use for a given service, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-comment">//TODO Do you business...</span>
}
@ -136,28 +136,28 @@ you would like to use for a given service, as shown in the following example:</p
@@ -136,28 +136,28 @@ you would like to use for a given service, as shown in the following example:</p
};
}
}</pre></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_multiple_resttemplate_objects"href="#_multiple_resttemplate_objects"></a>2.5 Multiple RestTemplate objects</h2></div></div></div><p>If you want a <codeclass="literal">RestTemplate</code> that is not load-balanced, create a <codeclass="literal">RestTemplate</code> bean and inject it.
To access the load-balanced <codeclass="literal">RestTemplate</code>, use the <codeclass="literal">@LoadBalanced</code> qualifier when you create your <codeclass="literal">@Bean</code>, as shown in the following example:\</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To access the load-balanced <codeclass="literal">RestTemplate</code>, use the <codeclass="literal">@LoadBalanced</code> qualifier when you create your <codeclass="literal">@Bean</code>, as shown in the following example:\</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -168,7 +168,7 @@ To access the load-balanced <code class="literal">RestTemplate</code>, use the <
@@ -168,7 +168,7 @@ To access the load-balanced <code class="literal">RestTemplate</code>, use the <
}</pre><divclass="important"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Important"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Important]"src="images/important.png"></td><thalign="left">Important</th></tr><tr><tdalign="left"valign="top"><p>Notice the use of the <codeclass="literal">@Primary</code> annotation on the plain <codeclass="literal">RestTemplate</code> declaration in the preceding example to disambiguate the unqualified <codeclass="literal">@Autowired</code> injection.</p></td></tr></table></div><divclass="tip"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Tip"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Tip]"src="images/tip.png"></td><thalign="left">Tip</th></tr><tr><tdalign="left"valign="top"><p>If you see errors such as <codeclass="literal">java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89</code>, try injecting <codeclass="literal">RestOperations</code> or setting <codeclass="literal">spring.aop.proxyTargetClass=true</code>.</p></td></tr></table></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="loadbalanced-webclient"href="#loadbalanced-webclient"></a>2.6 Spring WebFlux WebClient as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">WebClient</code> can be configured to use the <codeclass="literal">LoadBalancerClient</code>. <codeclass="literal">LoadBalancerExchangeFilterFunction</code> is auto-configured if <codeclass="literal">spring-webflux</code> is on the classpath. The following example shows how to configure a <codeclass="literal">WebClient</code> to use load balancer:</p><preclass="programlisting"><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">public</span><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">class</span> MyClass {
@ -210,19 +210,19 @@ You can also disable the creation of these beans by setting <code class="literal
@@ -210,19 +210,19 @@ You can also disable the creation of these beans by setting <code class="literal
This endpoint returns features available on the classpath and whether they are enabled.
The information returned includes the feature type, name, version, and vendor.</p><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_feature_types"href="#_feature_types"></a>2.9.1 Feature types</h3></div></div></div><p>There are two types of 'features': abstract and named.</p><p>Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as <codeclass="literal">DiscoveryClient</code>, <codeclass="literal">LoadBalancerClient</code>, or <codeclass="literal">LockService</code>.
The abstract class or interface is used to find a bean of that type in the context.
The version displayed is <codeclass="literal">bean.getClass().getPackage().getImplementationVersion()</code>.</p><p>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.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_declaring_features"href="#_declaring_features"></a>2.9.2 Declaring features</h3></div></div></div><p>Any module can declare any number of <codeclass="literal">HasFeature</code> beans, as shown in the following examples:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Bean</span></em>
The version displayed is <codeclass="literal">bean.getClass().getPackage().getImplementationVersion()</code>.</p><p>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.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_declaring_features"href="#_declaring_features"></a>2.9.2 Declaring features</h3></div></div></div><p>Any module can declare any number of <codeclass="literal">HasFeature</code> beans, as shown in the following examples:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Bean</xslthl:annotation>
@ -47,10 +47,10 @@ If you want to control the startup sequence, classes can be marked with an <code
@@ -47,10 +47,10 @@ If you want to control the startup sequence, classes can be marked with an <code
Use a separate package name for boot configuration classes and make sure that name is not already covered by your <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code> annotated configuration classes.</p></td></tr></table></div><p>The bootstrap process ends by injecting initializers into the main <codeclass="literal">SpringApplication</code> instance (which is the normal Spring Boot startup sequence, whether it is running as a standalone application or deployed in an application server).
First, a bootstrap context is created from the classes found in <codeclass="literal">spring.factories</code>.
Then, all <codeclass="literal">@Beans</code> of type <codeclass="literal">ApplicationContextInitializer</code> are added to the main <codeclass="literal">SpringApplication</code> before it is started.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="customizing-bootstrap-property-sources"href="#customizing-bootstrap-property-sources"></a>1.6 Customizing the Bootstrap Property Sources</h2></div></div></div><p>The default property source for external configuration added by the bootstrap process is the Spring Cloud Config Server, but you can add additional sources by adding beans of type <codeclass="literal">PropertySourceLocator</code> to the bootstrap context (through <codeclass="literal">spring.factories</code>).
For instance, you can insert additional properties from a different server or from a database.</p><p>As an example, consider the following custom locator:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
For instance, you can insert additional properties from a different server or from a database.</p><p>As an example, consider the following custom locator:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
Collections.<String, Object>singletonMap(<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-string">"property.from.sample.custom.source"</span>, <spanxmlns:d="http://docbook.org/ns/docbook"class="hl-string">"worked as intended"</span>));
@ -53,10 +53,10 @@ If you want to control the startup sequence, classes can be marked with an <code
@@ -53,10 +53,10 @@ If you want to control the startup sequence, classes can be marked with an <code
Use a separate package name for boot configuration classes and make sure that name is not already covered by your <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code> annotated configuration classes.</p></td></tr></table></div><p>The bootstrap process ends by injecting initializers into the main <codeclass="literal">SpringApplication</code> instance (which is the normal Spring Boot startup sequence, whether it is running as a standalone application or deployed in an application server).
First, a bootstrap context is created from the classes found in <codeclass="literal">spring.factories</code>.
Then, all <codeclass="literal">@Beans</code> of type <codeclass="literal">ApplicationContextInitializer</code> are added to the main <codeclass="literal">SpringApplication</code> before it is started.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="customizing-bootstrap-property-sources"href="#customizing-bootstrap-property-sources"></a>1.6 Customizing the Bootstrap Property Sources</h2></div></div></div><p>The default property source for external configuration added by the bootstrap process is the Spring Cloud Config Server, but you can add additional sources by adding beans of type <codeclass="literal">PropertySourceLocator</code> to the bootstrap context (through <codeclass="literal">spring.factories</code>).
For instance, you can insert additional properties from a different server or from a database.</p><p>As an example, consider the following custom locator:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
For instance, you can insert additional properties from a different server or from a database.</p><p>As an example, consider the following custom locator:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
Collections.<String, Object>singletonMap(<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-string">"property.from.sample.custom.source"</span>, <spanxmlns:d="http://docbook.org/ns/docbook"class="hl-string">"worked as intended"</span>));
@ -118,8 +118,8 @@ properties to set the order of the <code class="literal">DiscoveryClient</code>
@@ -118,8 +118,8 @@ properties to set the order of the <code class="literal">DiscoveryClient</code>
implementations provided by Spring Cloud, among others <codeclass="literal">ConsulDiscoveryClient</code>, <codeclass="literal">EurekaDiscoveryClient</code> and
<codeclass="literal">ZookeeperDiscoveryClient</code>. In order to do it, you just need to set the
<codeclass="literal">spring.cloud.{clientIdentifier}.discovery.order</code> (or <codeclass="literal">eureka.client.order</code> for Eureka) property to the desired value.</p></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_serviceregistry"href="#_serviceregistry"></a>2.2 ServiceRegistry</h2></div></div></div><p>Commons now provides a <codeclass="literal">ServiceRegistry</code> interface that provides methods such as <codeclass="literal">register(Registration)</code> and <codeclass="literal">deregister(Registration)</code>, which let you provide custom registered services.
<codeclass="literal">Registration</code> is a marker interface.</p><p>The following example shows the <codeclass="literal">ServiceRegistry</code> in use:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
<codeclass="literal">Registration</code> is a marker interface.</p><p>The following example shows the <codeclass="literal">ServiceRegistry</code> in use:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -147,18 +147,18 @@ Using POST to the same endpoint with a JSON body changes the status of the curre
@@ -147,18 +147,18 @@ Using POST to the same endpoint with a JSON body changes the status of the curre
The JSON body has to include the <codeclass="literal">status</code> field with the preferred value.
Please see the documentation of the <codeclass="literal">ServiceRegistry</code> implementation you use for the allowed values when updating the status and the values returned for the status.
For instance, Eureka’s supported statuses are <codeclass="literal">UP</code>, <codeclass="literal">DOWN</code>, <codeclass="literal">OUT_OF_SERVICE</code>, and <codeclass="literal">UNKNOWN</code>.</p></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_spring_resttemplate_as_a_load_balancer_client"href="#_spring_resttemplate_as_a_load_balancer_client"></a>2.3 Spring RestTemplate as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">RestTemplate</code> can be automatically configured to use ribbon.
To create a load-balanced <codeclass="literal">RestTemplate</code>, create a <codeclass="literal">RestTemplate</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To create a load-balanced <codeclass="literal">RestTemplate</code>, create a <codeclass="literal">RestTemplate</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -169,18 +169,18 @@ To create a load-balanced <code class="literal">RestTemplate</code>, create a <c
@@ -169,18 +169,18 @@ To create a load-balanced <code class="literal">RestTemplate</code>, create a <c
Individual applications must create it.</p></td></tr></table></div><p>The URI needs to use a virtual host name (that is, a service name, not a host name).
The Ribbon client is used to create a full physical address.
See <aclass="link"href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java"target="_top">RibbonAutoConfiguration</a> for details of how the <codeclass="literal">RestTemplate</code> is set up.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_spring_webclient_as_a_load_balancer_client"href="#_spring_webclient_as_a_load_balancer_client"></a>2.4 Spring WebClient as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">WebClient</code> can be automatically configured to use the <codeclass="literal">LoadBalancerClient</code>.
To create a load-balanced <codeclass="literal">WebClient</code>, create a <codeclass="literal">WebClient.Builder</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To create a load-balanced <codeclass="literal">WebClient</code>, create a <codeclass="literal">WebClient.Builder</code><codeclass="literal">@Bean</code> and use the <codeclass="literal">@LoadBalanced</code> qualifier, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -194,12 +194,12 @@ You can enable it by adding <a class="link" href="https://github.com/spring-proj
@@ -194,12 +194,12 @@ You can enable it by adding <a class="link" href="https://github.com/spring-proj
The load-balanced <codeclass="literal">RestTemplate</code> honors some of the Ribbon configuration values related to retrying failed requests.
You can use <codeclass="literal">client.ribbon.MaxAutoRetries</code>, <codeclass="literal">client.ribbon.MaxAutoRetriesNextServer</code>, and <codeclass="literal">client.ribbon.OkToRetryOnAllOperations</code> properties.
If you would like to disable the retry logic with Spring Retry on the classpath, you can set <codeclass="literal">spring.cloud.loadbalancer.retry.enabled=false</code>.
See the <aclass="link"href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties"target="_top">Ribbon documentation</a> for a description of what these properties do.</p><p>If you would like to implement a <codeclass="literal">BackOffPolicy</code> in your retries, you need to create a bean of type <codeclass="literal">LoadBalancedRetryFactory</code> and override the <codeclass="literal">createBackOffPolicy</code> method:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
See the <aclass="link"href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties"target="_top">Ribbon documentation</a> for a description of what these properties do.</p><p>If you would like to implement a <codeclass="literal">BackOffPolicy</code> in your retries, you need to create a bean of type <codeclass="literal">LoadBalancedRetryFactory</code> and override the <codeclass="literal">createBackOffPolicy</code> method:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -207,26 +207,26 @@ See the <a class="link" href="https://github.com/Netflix/ribbon/wiki/Getting-Sta
@@ -207,26 +207,26 @@ See the <a class="link" href="https://github.com/Netflix/ribbon/wiki/Getting-Sta
}
}</pre><divclass="note"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Note"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Note]"src="images/note.png"></td><thalign="left">Note</th></tr><tr><tdalign="left"valign="top"><p><codeclass="literal">client</code> in the preceding examples should be replaced with your Ribbon client’s name.</p></td></tr></table></div><p>If you want to add one or more <codeclass="literal">RetryListener</code> implementations to your retry functionality, you need to
create a bean of type <codeclass="literal">LoadBalancedRetryListenerFactory</code> and return the <codeclass="literal">RetryListener</code> array
you would like to use for a given service, as shown in the following example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
you would like to use for a given service, as shown in the following example:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-comment">//TODO Do you business...</span>
}
@ -235,28 +235,28 @@ you would like to use for a given service, as shown in the following example:</p
@@ -235,28 +235,28 @@ you would like to use for a given service, as shown in the following example:</p
};
}
}</pre></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_multiple_resttemplate_objects"href="#_multiple_resttemplate_objects"></a>2.5 Multiple RestTemplate objects</h2></div></div></div><p>If you want a <codeclass="literal">RestTemplate</code> that is not load-balanced, create a <codeclass="literal">RestTemplate</code> bean and inject it.
To access the load-balanced <codeclass="literal">RestTemplate</code>, use the <codeclass="literal">@LoadBalanced</code> qualifier when you create your <codeclass="literal">@Bean</code>, as shown in the following example:\</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
To access the load-balanced <codeclass="literal">RestTemplate</code>, use the <codeclass="literal">@LoadBalanced</code> qualifier when you create your <codeclass="literal">@Bean</code>, as shown in the following example:\</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Configuration</xslthl:annotation>
@ -267,7 +267,7 @@ To access the load-balanced <code class="literal">RestTemplate</code>, use the <
@@ -267,7 +267,7 @@ To access the load-balanced <code class="literal">RestTemplate</code>, use the <
}</pre><divclass="important"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Important"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Important]"src="images/important.png"></td><thalign="left">Important</th></tr><tr><tdalign="left"valign="top"><p>Notice the use of the <codeclass="literal">@Primary</code> annotation on the plain <codeclass="literal">RestTemplate</code> declaration in the preceding example to disambiguate the unqualified <codeclass="literal">@Autowired</code> injection.</p></td></tr></table></div><divclass="tip"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Tip"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Tip]"src="images/tip.png"></td><thalign="left">Tip</th></tr><tr><tdalign="left"valign="top"><p>If you see errors such as <codeclass="literal">java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89</code>, try injecting <codeclass="literal">RestOperations</code> or setting <codeclass="literal">spring.aop.proxyTargetClass=true</code>.</p></td></tr></table></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="loadbalanced-webclient"href="#loadbalanced-webclient"></a>2.6 Spring WebFlux WebClient as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">WebClient</code> can be configured to use the <codeclass="literal">LoadBalancerClient</code>. <codeclass="literal">LoadBalancerExchangeFilterFunction</code> is auto-configured if <codeclass="literal">spring-webflux</code> is on the classpath. The following example shows how to configure a <codeclass="literal">WebClient</code> to use load balancer:</p><preclass="programlisting"><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">public</span><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">class</span> MyClass {
@ -309,19 +309,19 @@ You can also disable the creation of these beans by setting <code class="literal
@@ -309,19 +309,19 @@ You can also disable the creation of these beans by setting <code class="literal
This endpoint returns features available on the classpath and whether they are enabled.
The information returned includes the feature type, name, version, and vendor.</p><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_feature_types"href="#_feature_types"></a>2.9.1 Feature types</h3></div></div></div><p>There are two types of 'features': abstract and named.</p><p>Abstract features are features where an interface or abstract class is defined and that an implementation the creates, such as <codeclass="literal">DiscoveryClient</code>, <codeclass="literal">LoadBalancerClient</code>, or <codeclass="literal">LockService</code>.
The abstract class or interface is used to find a bean of that type in the context.
The version displayed is <codeclass="literal">bean.getClass().getPackage().getImplementationVersion()</code>.</p><p>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.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_declaring_features"href="#_declaring_features"></a>2.9.2 Declaring features</h3></div></div></div><p>Any module can declare any number of <codeclass="literal">HasFeature</code> beans, as shown in the following examples:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Bean</span></em>
The version displayed is <codeclass="literal">bean.getClass().getPackage().getImplementationVersion()</code>.</p><p>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.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_declaring_features"href="#_declaring_features"></a>2.9.2 Declaring features</h3></div></div></div><p>Any module can declare any number of <codeclass="literal">HasFeature</code> beans, as shown in the following examples:</p><preclass="programlisting"><xslthl:annotationxmlns:xslthl="http://xslthl.sourceforge.net/">@Bean</xslthl:annotation>