diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/src/main/asciidoc/spring-cloud-netflix.adoc index 400c3bec..3283faef 100644 --- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc +++ b/docs/src/main/asciidoc/spring-cloud-netflix.adoc @@ -1127,6 +1127,18 @@ static class HystrixClientFallbackFactory implements FallbackFactory testClients; + + @FeignClient(name = "localapp", primary = false) + protected interface TestClient { + @RequestMapping(method = RequestMethod.GET, path = "/hello") + Hello getHello(); + + } + + @Configuration + @EnableAutoConfiguration + @RestController + @EnableFeignClients(clients = { TestClient.class} , + defaultConfiguration = TestDefaultFeignConfig.class) + @RibbonClient(name = "localapp", configuration = LocalRibbonClientConfiguration.class) + protected static class Application { + + @Bean + @Primary + public PrimaryTestClient primaryTestClient() { + return new PrimaryTestClient(); + } + + @RequestMapping(method = RequestMethod.GET, path = "/hello") + public Hello getHello() { + return new Hello(HELLO_WORLD_1); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(Application.class) + .properties("spring.application.name=feignclienttest", + "management.contextPath=/admin") + .run(args); + } + } + + @Test + public void testClientType() { + assertThat(this.testClient).as("testClient was of wrong type").isInstanceOf(PrimaryTestClient.class); + } + + @Test + public void testClientCount() { + assertThat(this.testClients).as("testClients was wrong").hasSize(2); + } + + @Test + public void testSimpleType() { + Hello hello = this.testClient.getHello(); + assertNull("hello was null", hello); + } + + protected static class PrimaryTestClient implements TestClient { + @Override + public Hello getHello() { + return null; + } + } + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class Hello { + private String message; + } + + @Configuration + public static class TestDefaultFeignConfig { + @Bean + Logger.Level feignLoggerLevel() { + return Logger.Level.FULL; + } + } + + // Load balancer with fixed server list for "local" pointing to localhost + @Configuration + public static class LocalRibbonClientConfiguration { + + @Value("${local.server.port}") + private int port = 0; + + @Bean + public ServerList ribbonServerList() { + return new StaticServerList<>(new Server("localhost", this.port)); + } + + } +}