@ -32,10 +32,14 @@ it will resolve the service in the Eureka service registry. If you
@@ -32,10 +32,14 @@ it will resolve the service in the Eureka service registry. If you
don’t want to use Eureka, you can simply configure a list of servers
in your external configuration (see
<aclass="link"href="">above for example</a>).</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="spring-cloud-feign-overriding-defaults"href="#spring-cloud-feign-overriding-defaults"></a>1.2 Overriding Feign Defaults</h2></div></div></div><p>A central concept in Spring Cloud’s Feign support is that of the named client. Each feign client is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer using the <codeclass="literal">@FeignClient</code> annotation. Spring Cloud creates a new ensemble as an
<codeclass="literal">ApplicationContext</code> on demand for each named client using <codeclass="literal">FeignClientsConfiguration</code>. This contains (amongst other things) an <codeclass="literal">feign.Decoder</code>, a <codeclass="literal">feign.Encoder</code>, and a <codeclass="literal">feign.Contract</code>.</p><p>Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the <codeclass="literal">FeignClientsConfiguration</code>) using <codeclass="literal">@FeignClient</code>. Example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "stores", configuration = FooConfiguration.class)</span></em>
<codeclass="literal">ApplicationContext</code> on demand for each named client using <codeclass="literal">FeignClientsConfiguration</code>. This contains (amongst other things) an <codeclass="literal">feign.Decoder</code>, a <codeclass="literal">feign.Encoder</code>, and a <codeclass="literal">feign.Contract</code>.
It is possible to override the name of that ensemble by using the <codeclass="literal">contextId</code>
attribute of the <codeclass="literal">@FeignClient</code> annotation.</p><p>Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the <codeclass="literal">FeignClientsConfiguration</code>) using <codeclass="literal">@FeignClient</code>. Example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "stores", configuration = FooConfiguration.class)</span></em>
}</pre><p>In this case the client is composed from the components already in <codeclass="literal">FeignClientsConfiguration</code> together with any in <codeclass="literal">FooConfiguration</code> (where the latter will override the former).</p><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">FooConfiguration</code> does not need to be annotated with <codeclass="literal">@Configuration</code>. However, if it is, then take care to exclude it from any <codeclass="literal">@ComponentScan</code> that would otherwise include this configuration as it will become the default source for <codeclass="literal">feign.Decoder</code>, <codeclass="literal">feign.Encoder</code>, <codeclass="literal">feign.Contract</code>, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code>, or it can be explicitly excluded in <codeclass="literal">@ComponentScan</code>.</p></td></tr></table></div><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>The <codeclass="literal">serviceId</code> attribute is now deprecated in favor of the <codeclass="literal">name</code> attribute.</p></td></tr></table></div><divclass="warning"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Warning"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Warning]"src="images/warning.png"></td><thalign="left">Warning</th></tr><tr><tdalign="left"valign="top"><p>Previously, using the <codeclass="literal">url</code> attribute, did not require the <codeclass="literal">name</code> attribute. Using <codeclass="literal">name</code> is now required.</p></td></tr></table></div><p>Placeholders are supported in the <codeclass="literal">name</code> and <codeclass="literal">url</code> attributes.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "${feign.name}", url = "${feign.url}")</span></em>
}</pre><p>In this case the client is composed from the components already in <codeclass="literal">FeignClientsConfiguration</code> together with any in <codeclass="literal">FooConfiguration</code> (where the latter will override the former).</p><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">FooConfiguration</code> does not need to be annotated with <codeclass="literal">@Configuration</code>. However, if it is, then take care to exclude it from any <codeclass="literal">@ComponentScan</code> that would otherwise include this configuration as it will become the default source for <codeclass="literal">feign.Decoder</code>, <codeclass="literal">feign.Encoder</code>, <codeclass="literal">feign.Contract</code>, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code>, or it can be explicitly excluded in <codeclass="literal">@ComponentScan</code>.</p></td></tr></table></div><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>The <codeclass="literal">serviceId</code> attribute is now deprecated in favor of the <codeclass="literal">name</code> attribute.</p></td></tr></table></div><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>Using <codeclass="literal">contextId</code> attribute of the <codeclass="literal">@FeignClient</code> annotation in addition to changing the name of
the <codeclass="literal">ApplicationContext</code> ensemble, it will override the alias of the client name
and it will be used as part of the name of the configuration bean created for that client.</p></td></tr></table></div><divclass="warning"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Warning"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Warning]"src="images/warning.png"></td><thalign="left">Warning</th></tr><tr><tdalign="left"valign="top"><p>Previously, using the <codeclass="literal">url</code> attribute, did not require the <codeclass="literal">name</code> attribute. Using <codeclass="literal">name</code> is now required.</p></td></tr></table></div><p>Placeholders are supported in the <codeclass="literal">name</code> and <codeclass="literal">url</code> attributes.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "${feign.name}", url = "${feign.url}")</span></em>
}</pre><p>Spring Cloud Netflix provides the following beans by default for feign (<codeclass="literal">BeanType</code> beanName: <codeclass="literal">ClassName</code>):</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem"><codeclass="literal">Decoder</code> feignDecoder: <codeclass="literal">ResponseEntityDecoder</code> (which wraps a <codeclass="literal">SpringDecoder</code>)</li><liclass="listitem"><codeclass="literal">Encoder</code> feignEncoder: <codeclass="literal">SpringEncoder</code></li><liclass="listitem"><codeclass="literal">Logger</code> feignLogger: <codeclass="literal">Slf4jLogger</code></li><liclass="listitem"><codeclass="literal">Contract</code> feignContract: <codeclass="literal">SpringMvcContract</code></li><liclass="listitem"><codeclass="literal">Feign.Builder</code> feignBuilder: <codeclass="literal">HystrixFeign.Builder</code></li><liclass="listitem"><codeclass="literal">Client</code> feignClient: if Ribbon is enabled it is a <codeclass="literal">LoadBalancerFeignClient</code>, otherwise the default feign client is used.</li></ul></div><p>The OkHttpClient and ApacheHttpClient feign clients can be used by setting <codeclass="literal">feign.okhttp.enabled</code> or <codeclass="literal">feign.httpclient.enabled</code> to <codeclass="literal">true</code>, respectively, and having them on the classpath.
@ -85,7 +89,16 @@ thread isolation strategy for Hystrix to `SEMAPHORE</code> or disable Hystrix in
@@ -85,7 +89,16 @@ thread isolation strategy for Hystrix to `SEMAPHORE</code> or disable Hystrix in
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-attribute"> strategy</span>: SEMAPHORE</pre></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_creating_feign_clients_manually"href="#_creating_feign_clients_manually"></a>1.3 Creating Feign Clients Manually</h2></div></div></div><p>In some cases it might be necessary to customize your Feign Clients in a way that is not
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-attribute"> strategy</span>: SEMAPHORE</pre><p>If we want to create multiple feign clients with the same name or url
so that they would point to the same server but each with a different custom configuration then
we have to use <codeclass="literal">contextId</code> attribute of the <codeclass="literal">@FeignClient</code> in order to avoid name
collision of these configuration beans.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class)</span></em>
}</pre></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_creating_feign_clients_manually"href="#_creating_feign_clients_manually"></a>1.3 Creating Feign Clients Manually</h2></div></div></div><p>In some cases it might be necessary to customize your Feign Clients in a way that is not
possible using the methods above. In this case you can create Clients using the
<aclass="link"href="https://github.com/OpenFeign/feign/#basics"target="_top">Feign Builder API</a>. Below is an example
which creates two Feign Clients with the same interface but configures each one with
@ -33,10 +33,14 @@ it will resolve the service in the Eureka service registry. If you
@@ -33,10 +33,14 @@ it will resolve the service in the Eureka service registry. If you
don’t want to use Eureka, you can simply configure a list of servers
in your external configuration (see
<aclass="link"href="#">above for example</a>).</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="spring-cloud-feign-overriding-defaults"href="#spring-cloud-feign-overriding-defaults"></a>1.2 Overriding Feign Defaults</h2></div></div></div><p>A central concept in Spring Cloud’s Feign support is that of the named client. Each feign client is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer using the <codeclass="literal">@FeignClient</code> annotation. Spring Cloud creates a new ensemble as an
<codeclass="literal">ApplicationContext</code> on demand for each named client using <codeclass="literal">FeignClientsConfiguration</code>. This contains (amongst other things) an <codeclass="literal">feign.Decoder</code>, a <codeclass="literal">feign.Encoder</code>, and a <codeclass="literal">feign.Contract</code>.</p><p>Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the <codeclass="literal">FeignClientsConfiguration</code>) using <codeclass="literal">@FeignClient</code>. Example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "stores", configuration = FooConfiguration.class)</span></em>
<codeclass="literal">ApplicationContext</code> on demand for each named client using <codeclass="literal">FeignClientsConfiguration</code>. This contains (amongst other things) an <codeclass="literal">feign.Decoder</code>, a <codeclass="literal">feign.Encoder</code>, and a <codeclass="literal">feign.Contract</code>.
It is possible to override the name of that ensemble by using the <codeclass="literal">contextId</code>
attribute of the <codeclass="literal">@FeignClient</code> annotation.</p><p>Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the <codeclass="literal">FeignClientsConfiguration</code>) using <codeclass="literal">@FeignClient</code>. Example:</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "stores", configuration = FooConfiguration.class)</span></em>
}</pre><p>In this case the client is composed from the components already in <codeclass="literal">FeignClientsConfiguration</code> together with any in <codeclass="literal">FooConfiguration</code> (where the latter will override the former).</p><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">FooConfiguration</code> does not need to be annotated with <codeclass="literal">@Configuration</code>. However, if it is, then take care to exclude it from any <codeclass="literal">@ComponentScan</code> that would otherwise include this configuration as it will become the default source for <codeclass="literal">feign.Decoder</code>, <codeclass="literal">feign.Encoder</code>, <codeclass="literal">feign.Contract</code>, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code>, or it can be explicitly excluded in <codeclass="literal">@ComponentScan</code>.</p></td></tr></table></div><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>The <codeclass="literal">serviceId</code> attribute is now deprecated in favor of the <codeclass="literal">name</code> attribute.</p></td></tr></table></div><divclass="warning"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Warning"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Warning]"src="images/warning.png"></td><thalign="left">Warning</th></tr><tr><tdalign="left"valign="top"><p>Previously, using the <codeclass="literal">url</code> attribute, did not require the <codeclass="literal">name</code> attribute. Using <codeclass="literal">name</code> is now required.</p></td></tr></table></div><p>Placeholders are supported in the <codeclass="literal">name</code> and <codeclass="literal">url</code> attributes.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "${feign.name}", url = "${feign.url}")</span></em>
}</pre><p>In this case the client is composed from the components already in <codeclass="literal">FeignClientsConfiguration</code> together with any in <codeclass="literal">FooConfiguration</code> (where the latter will override the former).</p><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">FooConfiguration</code> does not need to be annotated with <codeclass="literal">@Configuration</code>. However, if it is, then take care to exclude it from any <codeclass="literal">@ComponentScan</code> that would otherwise include this configuration as it will become the default source for <codeclass="literal">feign.Decoder</code>, <codeclass="literal">feign.Encoder</code>, <codeclass="literal">feign.Contract</code>, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any <codeclass="literal">@ComponentScan</code> or <codeclass="literal">@SpringBootApplication</code>, or it can be explicitly excluded in <codeclass="literal">@ComponentScan</code>.</p></td></tr></table></div><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>The <codeclass="literal">serviceId</code> attribute is now deprecated in favor of the <codeclass="literal">name</code> attribute.</p></td></tr></table></div><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>Using <codeclass="literal">contextId</code> attribute of the <codeclass="literal">@FeignClient</code> annotation in addition to changing the name of
the <codeclass="literal">ApplicationContext</code> ensemble, it will override the alias of the client name
and it will be used as part of the name of the configuration bean created for that client.</p></td></tr></table></div><divclass="warning"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Warning"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Warning]"src="images/warning.png"></td><thalign="left">Warning</th></tr><tr><tdalign="left"valign="top"><p>Previously, using the <codeclass="literal">url</code> attribute, did not require the <codeclass="literal">name</code> attribute. Using <codeclass="literal">name</code> is now required.</p></td></tr></table></div><p>Placeholders are supported in the <codeclass="literal">name</code> and <codeclass="literal">url</code> attributes.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(name = "${feign.name}", url = "${feign.url}")</span></em>
}</pre><p>Spring Cloud Netflix provides the following beans by default for feign (<codeclass="literal">BeanType</code> beanName: <codeclass="literal">ClassName</code>):</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem"><codeclass="literal">Decoder</code> feignDecoder: <codeclass="literal">ResponseEntityDecoder</code> (which wraps a <codeclass="literal">SpringDecoder</code>)</li><liclass="listitem"><codeclass="literal">Encoder</code> feignEncoder: <codeclass="literal">SpringEncoder</code></li><liclass="listitem"><codeclass="literal">Logger</code> feignLogger: <codeclass="literal">Slf4jLogger</code></li><liclass="listitem"><codeclass="literal">Contract</code> feignContract: <codeclass="literal">SpringMvcContract</code></li><liclass="listitem"><codeclass="literal">Feign.Builder</code> feignBuilder: <codeclass="literal">HystrixFeign.Builder</code></li><liclass="listitem"><codeclass="literal">Client</code> feignClient: if Ribbon is enabled it is a <codeclass="literal">LoadBalancerFeignClient</code>, otherwise the default feign client is used.</li></ul></div><p>The OkHttpClient and ApacheHttpClient feign clients can be used by setting <codeclass="literal">feign.okhttp.enabled</code> or <codeclass="literal">feign.httpclient.enabled</code> to <codeclass="literal">true</code>, respectively, and having them on the classpath.
@ -86,7 +90,16 @@ thread isolation strategy for Hystrix to `SEMAPHORE</code> or disable Hystrix in
@@ -86,7 +90,16 @@ thread isolation strategy for Hystrix to `SEMAPHORE</code> or disable Hystrix in
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-attribute"> strategy</span>: SEMAPHORE</pre></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_creating_feign_clients_manually"href="#_creating_feign_clients_manually"></a>1.3 Creating Feign Clients Manually</h2></div></div></div><p>In some cases it might be necessary to customize your Feign Clients in a way that is not
<spanxmlns:d="http://docbook.org/ns/docbook"class="hl-attribute"> strategy</span>: SEMAPHORE</pre><p>If we want to create multiple feign clients with the same name or url
so that they would point to the same server but each with a different custom configuration then
we have to use <codeclass="literal">contextId</code> attribute of the <codeclass="literal">@FeignClient</code> in order to avoid name
collision of these configuration beans.</p><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class)</span></em>
}</pre></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_creating_feign_clients_manually"href="#_creating_feign_clients_manually"></a>1.3 Creating Feign Clients Manually</h2></div></div></div><p>In some cases it might be necessary to customize your Feign Clients in a way that is not
possible using the methods above. In this case you can create Clients using the
<aclass="link"href="https://github.com/OpenFeign/feign/#basics"target="_top">Feign Builder API</a>. Below is an example
which creates two Feign Clients with the same interface but configures each one with
<simpara>A central concept in Spring Cloud’s Feign support is that of the named client. Each feign client is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer using the <literal>@FeignClient</literal> annotation. Spring Cloud creates a new ensemble as an
<literal>ApplicationContext</literal> on demand for each named client using <literal>FeignClientsConfiguration</literal>. This contains (amongst other things) an <literal>feign.Decoder</literal>, a <literal>feign.Encoder</literal>, and a <literal>feign.Contract</literal>.</simpara>
<literal>ApplicationContext</literal> on demand for each named client using <literal>FeignClientsConfiguration</literal>. This contains (amongst other things) an <literal>feign.Decoder</literal>, a <literal>feign.Encoder</literal>, and a <literal>feign.Contract</literal>.
It is possible to override the name of that ensemble by using the <literal>contextId</literal>
attribute of the <literal>@FeignClient</literal> annotation.</simpara>
<simpara>Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the <literal>FeignClientsConfiguration</literal>) using <literal>@FeignClient</literal>. Example:</simpara>
@ -74,6 +76,11 @@ public interface StoreClient {
@@ -74,6 +76,11 @@ public interface StoreClient {
<note>
<simpara>The <literal>serviceId</literal> attribute is now deprecated in favor of the <literal>name</literal> attribute.</simpara>
</note>
<note>
<simpara>Using <literal>contextId</literal> attribute of the <literal>@FeignClient</literal> annotation in addition to changing the name of
the <literal>ApplicationContext</literal> ensemble, it will override the alias of the client name
and it will be used as part of the name of the configuration bean created for that client.</simpara>
</note>
<warning>
<simpara>Previously, using the <literal>url</literal> attribute, did not require the <literal>name</literal> attribute. Using <literal>name</literal> is now required.</simpara>