diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java index 8abe20ae..8c1d22a8 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/ribbon/FeignRibbonClientAutoConfiguration.java @@ -56,12 +56,14 @@ public class FeignRibbonClientAutoConfiguration { @Bean @ConditionalOnMissingBean public Client feignClient(CachingSpringLoadBalancerFactory cachingFactory) { - return new LoadBalancerFeignClient(new Client.Default(null, null), cachingFactory); + return new LoadBalancerFeignClient(new Client.Default(null, null), + cachingFactory); } @Configuration @ConditionalOnClass(ApacheHttpClient.class) @ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true) + @ConditionalOnMissingBean(Client.class) protected static class HttpClientConfiguration { @Autowired(required = false) @@ -86,6 +88,7 @@ public class FeignRibbonClientAutoConfiguration { @Configuration @ConditionalOnClass(OkHttpClient.class) @ConditionalOnProperty(value = "feign.okhttp.enabled", matchIfMissing = true) + @ConditionalOnMissingBean(Client.class) protected static class OkHttpConfiguration { @Autowired(required = false) diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java index 1c0135b9..a9b7b519 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java @@ -20,8 +20,7 @@ import org.junit.Ignore; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import org.springframework.cloud.netflix.zuul.SampleZuulProxyApplicationTests; -import org.springframework.cloud.netflix.zuul.SimpleZuulServerApplicationTests; +import org.springframework.cloud.netflix.feign.valid.FeignHttpClientTests; /** * A test suite for probing weird ordering problems in the tests. @@ -29,8 +28,7 @@ import org.springframework.cloud.netflix.zuul.SimpleZuulServerApplicationTests; * @author Dave Syer */ @RunWith(Suite.class) -@SuiteClasses({ SimpleZuulServerApplicationTests.class, - SampleZuulProxyApplicationTests.class }) +@SuiteClasses({ FeignHttpClientTests.class }) @Ignore public class AdhocTestSuite { diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignHttpClientTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignHttpClientTests.java index 0c5e486a..1fe5b64c 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignHttpClientTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignHttpClientTests.java @@ -16,14 +16,6 @@ package org.springframework.cloud.netflix.feign.valid; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -51,6 +43,14 @@ import org.springframework.web.bind.annotation.RestController; import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.ServerList; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + import feign.Client; import lombok.AllArgsConstructor; import lombok.Data; @@ -63,7 +63,7 @@ import lombok.NoArgsConstructor; @SpringApplicationConfiguration(classes = FeignHttpClientTests.Application.class) @WebAppConfiguration @IntegrationTest({ "server.port=0", "spring.application.name=feignclienttest", - "feign.hystrix.enabled=false" }) + "feign.hystrix.enabled=false", "feign.okhttp.enabled=false" }) @DirtiesContext public class FeignHttpClientTests { @@ -80,28 +80,30 @@ public class FeignHttpClientTests { private UserClient userClient; @FeignClient("localapp") - protected interface TestClient extends BaseTestClient { } + protected interface TestClient extends BaseTestClient { + } protected interface BaseTestClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") Hello getHello(); @RequestMapping(method = RequestMethod.PATCH, value = "/hellop") - ResponseEntity patchHello(); + ResponseEntity patchHello(Hello hello); } protected interface UserService { - @RequestMapping(method = RequestMethod.GET, value ="/users/{id}") + @RequestMapping(method = RequestMethod.GET, value = "/users/{id}") User getUser(@PathVariable("id") long id); } @FeignClient("localapp") - protected interface UserClient extends UserService { } + protected interface UserClient extends UserService { + } @Configuration @EnableAutoConfiguration @RestController - @EnableFeignClients(clients = {TestClient.class, UserClient.class}) + @EnableFeignClients(clients = { TestClient.class, UserClient.class }) @RibbonClient(name = "localapp", configuration = LocalRibbonClientConfiguration.class) protected static class Application implements UserService { @@ -121,9 +123,10 @@ public class FeignHttpClientTests { } public static void main(String[] args) { - new SpringApplicationBuilder(Application.class).properties( - "spring.application.name=feignclienttest", - "management.contextPath=/admin").run(args); + new SpringApplicationBuilder(Application.class) + .properties("spring.application.name=feignclienttest", + "management.contextPath=/admin") + .run(args); } } @@ -136,7 +139,7 @@ public class FeignHttpClientTests { @Test public void testPatch() { - ResponseEntity response = this.testClient.patchHello(); + ResponseEntity response = this.testClient.patchHello(new Hello("foo")); assertThat(response, is(notNullValue())); String header = response.getHeaders().getFirst("X-Hello"); assertThat(header, equalTo("hello world patch"));