diff --git a/docs/pom.xml b/docs/pom.xml
index f8d5f7a3..5ce54fd8 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloudspring-cloud-openfeign
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.1.BUILD-SNAPSHOTspring-cloud-openfeign-docspom
diff --git a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc
index 39df827f..86aa25a8 100644
--- a/docs/src/main/asciidoc/spring-cloud-openfeign.adoc
+++ b/docs/src/main/asciidoc/spring-cloud-openfeign.adoc
@@ -73,6 +73,8 @@ in your external configuration (see
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 `@FeignClient` annotation. Spring Cloud creates a new ensemble as an
`ApplicationContext` on demand for each named client using `FeignClientsConfiguration`. This contains (amongst other things) an `feign.Decoder`, a `feign.Encoder`, and a `feign.Contract`.
+It is possible to override the name of that ensemble by using the `contextId`
+attribute of the `@FeignClient` annotation.
Spring Cloud lets you take full control of the feign client by declaring additional configuration (on top of the `FeignClientsConfiguration`) using `@FeignClient`. Example:
@@ -90,6 +92,10 @@ NOTE: `FooConfiguration` does not need to be annotated with `@Configuration`. Ho
NOTE: The `serviceId` attribute is now deprecated in favor of the `name` attribute.
+NOTE: Using `contextId` attribute of the `@FeignClient` annotation in addition to changing the name of
+the `ApplicationContext` 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.
+
WARNING: Previously, using the `url` attribute, did not require the `name` attribute. Using `name` is now required.
Placeholders are supported in the `name` and `url` attributes.
@@ -206,6 +212,27 @@ hystrix:
strategy: SEMAPHORE
----
+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 `contextId` attribute of the `@FeignClient` in order to avoid name
+collision of these configuration beans.
+
+[source,java,indent=0]
+----
+@FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class)
+public interface FooClient {
+ //..
+}
+----
+
+[source,java,indent=0]
+----
+@FeignClient(contextId = "barClient", name = "stores", configuration = BarConfiguration.class)
+public interface BarClient {
+ //..
+}
+----
+
=== Creating Feign Clients Manually
In some cases it might be necessary to customize your Feign Clients in a way that is not
diff --git a/pom.xml b/pom.xml
index 046cbd79..a2b87506 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0spring-cloud-openfeign
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.1.BUILD-SNAPSHOTpomSpring Cloud OpenFeignSpring Cloud OpenFeignorg.springframework.cloudspring-cloud-build
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.3.BUILD-SNAPSHOT
@@ -22,8 +22,8 @@
${basedir}2.7.3
- 2.1.0.BUILD-SNAPSHOT
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.1.BUILD-SNAPSHOT
+ 2.1.1.BUILD-SNAPSHOT3.6.1
diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml
index f78f2560..78476ceb 100644
--- a/spring-cloud-openfeign-core/pom.xml
+++ b/spring-cloud-openfeign-core/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloudspring-cloud-openfeign
- 2.1.0.BUILD-SNAPSHOT
+ 2.1.1.BUILD-SNAPSHOT..spring-cloud-openfeign-core
diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClient.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClient.java
index 59d58bb1..17c63bed 100644
--- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClient.java
+++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClient.java
@@ -54,6 +54,11 @@ public @interface FeignClient {
@Deprecated
String serviceId() default "";
+ /**
+ * This will be used as the bean name instead of name if present, but will not be used as a service id.
+ */
+ String contextId() default "";
+
/**
* The service id with optional protocol prefix. Synonym for {@link #value() value}.
*/
diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientBuilder.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientBuilder.java
index 3c0908ad..626a8284 100644
--- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientBuilder.java
+++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientBuilder.java
@@ -49,6 +49,7 @@ public class FeignClientBuilder {
this.feignClientFactoryBean.setApplicationContext(applicationContext);
this.feignClientFactoryBean.setType(type);
this.feignClientFactoryBean.setName(FeignClientsRegistrar.getName(name));
+ this.feignClientFactoryBean.setContextId(FeignClientsRegistrar.getName(name));
// preset default values - these values resemble the default values on the
// FeignClient annotation
this.url("").path("").decode404(false).fallback(void.class)
@@ -60,6 +61,11 @@ public class FeignClientBuilder {
return this;
}
+ public Builder contextId(final String contextId) {
+ this.feignClientFactoryBean.setContextId(contextId);
+ return this;
+ }
+
public Builder path(final String path) {
this.feignClientFactoryBean.setPath(FeignClientsRegistrar.getPath(path));
return this;
diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
index d8fab63f..2b0f1b08 100644
--- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
+++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
@@ -60,6 +60,8 @@ class FeignClientFactoryBean implements FactoryBean