From 10c69929354e4f33e5d8d8fe3d79c120fe93e182 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 11 Feb 2021 14:14:19 +0000 Subject: [PATCH 1/4] Update SNAPSHOT to 2.2.7.RELEASE --- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 39 ++++++++++--------- pom.xml | 8 ++-- spring-cloud-openfeign-core/pom.xml | 2 +- .../encoding/FeignPageableEncodingTests.java | 10 +++-- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 2b898e00..d9e2e0ec 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE spring-cloud-openfeign-docs pom diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 8d9d569e..01c9fc45 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -1,26 +1,27 @@ |=== |Name | Default | Description -|feign.circuitbreaker.enabled | false | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker. +|feign.autoconfiguration.jackson.enabled | `false` | If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding. +|feign.circuitbreaker.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker. |feign.client.config | | -|feign.client.decode-slash | true | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`. -|feign.client.default-config | default | -|feign.client.default-to-properties | true | -|feign.compression.request.enabled | false | Enables the request sent by Feign to be compressed. -|feign.compression.request.mime-types | [text/xml, application/xml, application/json] | The list of supported mime types. -|feign.compression.request.min-request-size | 2048 | The minimum threshold content size. -|feign.compression.response.enabled | false | Enables the response from Feign to be compressed. -|feign.compression.response.useGzipDecoder | false | Enables the default gzip decoder to be used. -|feign.httpclient.connection-timeout | 2000 | -|feign.httpclient.connection-timer-repeat | 3000 | -|feign.httpclient.disable-ssl-validation | false | -|feign.httpclient.enabled | true | Enables the use of the Apache HTTP Client by Feign. -|feign.httpclient.follow-redirects | true | -|feign.httpclient.max-connections | 200 | -|feign.httpclient.max-connections-per-route | 50 | -|feign.httpclient.time-to-live | 900 | +|feign.client.decode-slash | `true` | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`. +|feign.client.default-config | `default` | +|feign.client.default-to-properties | `true` | +|feign.compression.request.enabled | `false` | Enables the request sent by Feign to be compressed. +|feign.compression.request.mime-types | `[text/xml, application/xml, application/json]` | The list of supported mime types. +|feign.compression.request.min-request-size | `2048` | The minimum threshold content size. +|feign.compression.response.enabled | `false` | Enables the response from Feign to be compressed. +|feign.compression.response.useGzipDecoder | `false` | Enables the default gzip decoder to be used. +|feign.httpclient.connection-timeout | `2000` | +|feign.httpclient.connection-timer-repeat | `3000` | +|feign.httpclient.disable-ssl-validation | `false` | +|feign.httpclient.enabled | `true` | Enables the use of the Apache HTTP Client by Feign. +|feign.httpclient.follow-redirects | `true` | +|feign.httpclient.max-connections | `200` | +|feign.httpclient.max-connections-per-route | `50` | +|feign.httpclient.time-to-live | `900` | |feign.httpclient.time-to-live-unit | | -|feign.hystrix.enabled | false | If true, an OpenFeign client will be wrapped with a Hystrix circuit breaker. -|feign.okhttp.enabled | false | Enables the use of the OK HTTP Client by Feign. +|feign.hystrix.enabled | `false` | If true, an OpenFeign client will be wrapped with a Hystrix circuit breaker. +|feign.okhttp.enabled | `false` | Enables the use of the OK HTTP Client by Feign. |=== \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d71f240..1b9bde57 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.1.RELEASE + 2.3.2.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.7.BUILD-SNAPSHOT - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE + 2.2.7.RELEASE 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c88064b4..19232156 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java index 40f530a3..0f163bdb 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java @@ -101,7 +101,8 @@ public class FeignPageableEncodingTests { Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty"); // when - final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); + final ResponseEntity> response = this.invoiceClient + .getInvoicesPaged(pageable); // then assertThat(response).isNotNull(); @@ -125,11 +126,12 @@ public class FeignPageableEncodingTests { @Test public void testPageableWithMultipleSort() { // given - Pageable pageable = PageRequest.of(0, 10, - Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2"))); + Pageable pageable = PageRequest.of(0, 10, Sort + .by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2"))); // when - final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); + final ResponseEntity> response = this.invoiceClient + .getInvoicesPaged(pageable); // then assertThat(response).isNotNull(); diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 6d5aabcd..c9a39279 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.2.BUILD-SNAPSHOT + 2.3.2.RELEASE spring-cloud-openfeign-dependencies - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index c83ad3a3..cd15dd8d 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.7.RELEASE .. spring-cloud-starter-openfeign From ce7a55a484c9d51c60a35becc467c62728a5b9bc Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 11 Feb 2021 14:15:44 +0000 Subject: [PATCH 2/4] Going back to snapshots --- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 39 +++++++++---------- pom.xml | 8 ++-- spring-cloud-openfeign-core/pom.xml | 2 +- .../encoding/FeignPageableEncodingTests.java | 10 ++--- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 7 files changed, 32 insertions(+), 35 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index d9e2e0ec..2b898e00 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 01c9fc45..8d9d569e 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -1,27 +1,26 @@ |=== |Name | Default | Description -|feign.autoconfiguration.jackson.enabled | `false` | If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding. -|feign.circuitbreaker.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker. +|feign.circuitbreaker.enabled | false | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker. |feign.client.config | | -|feign.client.decode-slash | `true` | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`. -|feign.client.default-config | `default` | -|feign.client.default-to-properties | `true` | -|feign.compression.request.enabled | `false` | Enables the request sent by Feign to be compressed. -|feign.compression.request.mime-types | `[text/xml, application/xml, application/json]` | The list of supported mime types. -|feign.compression.request.min-request-size | `2048` | The minimum threshold content size. -|feign.compression.response.enabled | `false` | Enables the response from Feign to be compressed. -|feign.compression.response.useGzipDecoder | `false` | Enables the default gzip decoder to be used. -|feign.httpclient.connection-timeout | `2000` | -|feign.httpclient.connection-timer-repeat | `3000` | -|feign.httpclient.disable-ssl-validation | `false` | -|feign.httpclient.enabled | `true` | Enables the use of the Apache HTTP Client by Feign. -|feign.httpclient.follow-redirects | `true` | -|feign.httpclient.max-connections | `200` | -|feign.httpclient.max-connections-per-route | `50` | -|feign.httpclient.time-to-live | `900` | +|feign.client.decode-slash | true | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`. +|feign.client.default-config | default | +|feign.client.default-to-properties | true | +|feign.compression.request.enabled | false | Enables the request sent by Feign to be compressed. +|feign.compression.request.mime-types | [text/xml, application/xml, application/json] | The list of supported mime types. +|feign.compression.request.min-request-size | 2048 | The minimum threshold content size. +|feign.compression.response.enabled | false | Enables the response from Feign to be compressed. +|feign.compression.response.useGzipDecoder | false | Enables the default gzip decoder to be used. +|feign.httpclient.connection-timeout | 2000 | +|feign.httpclient.connection-timer-repeat | 3000 | +|feign.httpclient.disable-ssl-validation | false | +|feign.httpclient.enabled | true | Enables the use of the Apache HTTP Client by Feign. +|feign.httpclient.follow-redirects | true | +|feign.httpclient.max-connections | 200 | +|feign.httpclient.max-connections-per-route | 50 | +|feign.httpclient.time-to-live | 900 | |feign.httpclient.time-to-live-unit | | -|feign.hystrix.enabled | `false` | If true, an OpenFeign client will be wrapped with a Hystrix circuit breaker. -|feign.okhttp.enabled | `false` | Enables the use of the OK HTTP Client by Feign. +|feign.hystrix.enabled | false | If true, an OpenFeign client will be wrapped with a Hystrix circuit breaker. +|feign.okhttp.enabled | false | Enables the use of the OK HTTP Client by Feign. |=== \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1b9bde57..3d71f240 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.2.RELEASE + 2.3.1.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.7.RELEASE - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT + 2.2.7.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index 19232156..c88064b4 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java index 0f163bdb..40f530a3 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/encoding/FeignPageableEncodingTests.java @@ -101,8 +101,7 @@ public class FeignPageableEncodingTests { Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty"); // when - final ResponseEntity> response = this.invoiceClient - .getInvoicesPaged(pageable); + final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); // then assertThat(response).isNotNull(); @@ -126,12 +125,11 @@ public class FeignPageableEncodingTests { @Test public void testPageableWithMultipleSort() { // given - Pageable pageable = PageRequest.of(0, 10, Sort - .by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2"))); + Pageable pageable = PageRequest.of(0, 10, + Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2"))); // when - final ResponseEntity> response = this.invoiceClient - .getInvoicesPaged(pageable); + final ResponseEntity> response = this.invoiceClient.getInvoicesPaged(pageable); // then assertThat(response).isNotNull(); diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index c9a39279..6d5aabcd 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.2.RELEASE + 2.3.2.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index cd15dd8d..c83ad3a3 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.RELEASE + 2.2.7.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From 37e1c2fd111dcbb050c3e023e6b06d2a9d684d58 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 11 Feb 2021 14:15:44 +0000 Subject: [PATCH 3/4] Bumping versions to 2.2.8.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 2b898e00..240e275b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index 3d71f240..a945089f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.3.1.RELEASE + 2.3.2.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.11.3 - 2.2.7.BUILD-SNAPSHOT - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT 2.10 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index c88064b4..ba151a25 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 6d5aabcd..22f33b49 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.3.2.BUILD-SNAPSHOT + 2.3.3.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index c83ad3a3..33a0af3e 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.2.7.BUILD-SNAPSHOT + 2.2.8.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From a205afb88d661ec532811caec4dc7978db3f1eda Mon Sep 17 00:00:00 2001 From: Tim Peeters Date: Tue, 16 Feb 2021 16:28:39 +0100 Subject: [PATCH 4/4] Fixes #482 No bean found of type Targeter. (#483) --- .../openfeign/FeignAutoConfiguration.java | 35 ++++-- .../openfeign/HystrixDisabledConditions.java | 42 +++++++ .../FeignAutoConfigurationTests.java | 107 ++++++++++++++++++ 3 files changed, 175 insertions(+), 9 deletions(-) create mode 100644 spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/HystrixDisabledConditions.java create mode 100644 spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignAutoConfigurationTests.java diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java index a27c66d9..2250ee29 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignAutoConfiguration.java @@ -40,6 +40,7 @@ import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.impl.client.CloseableHttpClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -58,6 +59,7 @@ import org.springframework.cloud.openfeign.support.FeignHttpClientProperties; import org.springframework.cloud.openfeign.support.PageJacksonModule; import org.springframework.cloud.openfeign.support.SortJacksonModule; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.domain.Page; @@ -68,6 +70,7 @@ import org.springframework.data.domain.Sort; * @author Julien Roy * @author Grzegorz Poznachowski * @author Nikita Konev + * @author Tim Peeters */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(Feign.class) @@ -114,8 +117,7 @@ public class FeignAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @ConditionalOnMissingClass({ "feign.hystrix.HystrixFeign", - "org.springframework.cloud.client.circuitbreaker.CircuitBreaker" }) + @Conditional(DefaultFeignTargeterConditions.class) protected static class DefaultFeignTargeterConfiguration { @Bean @@ -127,7 +129,10 @@ public class FeignAutoConfiguration { } @Configuration(proxyBeanMethods = false) + @Conditional(FeignCircuitBreakerDisabledConditions.class) @ConditionalOnClass(name = "feign.hystrix.HystrixFeign") + @ConditionalOnProperty(value = "feign.hystrix.enabled", havingValue = "true", + matchIfMissing = true) protected static class HystrixFeignTargeterConfiguration { @Bean @@ -140,15 +145,9 @@ public class FeignAutoConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnClass(CircuitBreaker.class) - @ConditionalOnProperty("feign.circuitbreaker.enabled") + @ConditionalOnProperty(value = "feign.circuitbreaker.enabled", havingValue = "true") protected static class CircuitBreakerPresentFeignTargeterConfiguration { - @Bean - @ConditionalOnMissingBean(CircuitBreakerFactory.class) - public Targeter defaultFeignTargeter() { - return new DefaultTargeter(); - } - @Bean @ConditionalOnMissingBean @ConditionalOnBean(CircuitBreakerFactory.class) @@ -286,4 +285,22 @@ public class FeignAutoConfiguration { } + static class DefaultFeignTargeterConditions extends AllNestedConditions { + + DefaultFeignTargeterConditions() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @Conditional(FeignCircuitBreakerDisabledConditions.class) + static class FeignCircuitBreakerDisabled { + + } + + @Conditional(HystrixDisabledConditions.class) + static class HystrixDisabled { + + } + + } + } diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/HystrixDisabledConditions.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/HystrixDisabledConditions.java new file mode 100644 index 00000000..fc02e1f9 --- /dev/null +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/HystrixDisabledConditions.java @@ -0,0 +1,42 @@ +/* + * Copyright 2013-2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.openfeign; + +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * @author Tim Peeters + */ +class HystrixDisabledConditions extends AnyNestedCondition { + + HystrixDisabledConditions() { + super(ConfigurationPhase.PARSE_CONFIGURATION); + } + + @ConditionalOnMissingClass("feign.hystrix.HystrixFeign") + static class HystrixFeignClassMissing { + + } + + @ConditionalOnProperty(value = "feign.hystrix.enabled", havingValue = "false") + static class HystrixFeignDisabled { + + } + +} diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignAutoConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignAutoConfigurationTests.java new file mode 100644 index 00000000..fa513dc7 --- /dev/null +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignAutoConfigurationTests.java @@ -0,0 +1,107 @@ +/* + * Copyright 2013-2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.openfeign; + +import feign.hystrix.HystrixFeign; +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; +import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; +import org.springframework.context.ConfigurableApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * @author Tim Peeters + */ +class FeignAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class)); + + @Test + void shouldInstantiateHystrixTargeterToMaintainBackwardsCompatibility() { + runner.run(ctx -> assertOnlyOneTargeterPresent(ctx, HystrixTargeter.class)); + } + + @Test + void shouldInstantiateHystrixTargeterWhenExplicitlyEnabled() { + runner.withPropertyValues("feign.hystrix.enabled=true") + .run(ctx -> assertOnlyOneTargeterPresent(ctx, HystrixTargeter.class)); + } + + @Test + void shouldInstantiateDefaultTargeterWhenHystrixIsDisabled() { + runner.withPropertyValues("feign.hystrix.enabled=false") + .run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class)); + } + + @Test + void shouldInstantiateDefaultTargeterWhenHystrixFeignClassIsMissing() { + runner.withPropertyValues("feign.hystrix.enabled=true") + .withClassLoader(new FilteredClassLoader(HystrixFeign.class)) + .run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class)); + } + + @Test + void shouldInstantiateDefaultTargeterWhenHystrixFeignAndCircuitBreakerClassesAreMissing() { + runner.withPropertyValues("feign.hystrix.enabled=true", + "feign.circuitbreaker.enabled=true") + .withClassLoader( + new FilteredClassLoader(HystrixFeign.class, CircuitBreaker.class)) + .run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class)); + } + + @Test + void shouldInstantiateDefaultTargeterWhenHystrixFeignClassIsMissingAndFeignCircuitBreakerIsDisabled() { + runner.withClassLoader(new FilteredClassLoader(HystrixFeign.class)) + .withPropertyValues("feign.circuitbreaker.enabled=false") + .run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class)); + } + + @Test + void shouldInstantiateFeignCircuitBreakerTargeterWhenEnabled() { + runner.withBean(CircuitBreakerFactory.class, + () -> mock(CircuitBreakerFactory.class)) + .withPropertyValues("feign.circuitbreaker.enabled=true") + .run(ctx -> assertOnlyOneTargeterPresent(ctx, + FeignCircuitBreakerTargeter.class)); + } + + @Test + void shouldInstantiateFeignCircuitBreakerTargeterWhenBothHystrixAndCircuitBreakerAreEnabled() { + runner.withBean(CircuitBreakerFactory.class, + () -> mock(CircuitBreakerFactory.class)) + .withPropertyValues("feign.hystrix.enabled=true", + "feign.circuitbreaker.enabled=true") + .run(ctx -> assertOnlyOneTargeterPresent(ctx, + FeignCircuitBreakerTargeter.class)); + } + + private void assertOnlyOneTargeterPresent(ConfigurableApplicationContext ctx, + Class beanClass) { + assertThat(ctx.getBeansOfType(Targeter.class)).hasSize(1) + .hasValueSatisfying(new Condition<>(beanClass::isInstance, String + .format("Targeter should be an instance of %s", beanClass))); + } + +}