Commit 1ede1458 by Spencer Gibb

Get RequestInterceptors from feign context.

Rather than pulling them from the generic context. fixes gh-683
parent f38e43a4
...@@ -117,4 +117,13 @@ public class FeignClientFactory implements DisposableBean, ApplicationContextAwa ...@@ -117,4 +117,13 @@ public class FeignClientFactory implements DisposableBean, ApplicationContextAwa
return null; return null;
} }
public <C> Map<String, C> getInstances(String name, Class<C> type) {
AnnotationConfigApplicationContext context = getContext(name);
if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, type).length > 0) {
return context.getBeansOfType(type);
}
return null;
}
} }
...@@ -100,7 +100,7 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A ...@@ -100,7 +100,7 @@ class FeignClientFactoryBean implements FactoryBean<Object>, InitializingBean, A
if (options != null) { if (options != null) {
builder.options(options); builder.options(options);
} }
Map<String, RequestInterceptor> requestInterceptors = this.context.getBeansOfType(RequestInterceptor.class); Map<String, RequestInterceptor> requestInterceptors = factory.getInstances(this.name, RequestInterceptor.class);
if (requestInterceptors != null) { if (requestInterceptors != null) {
builder.requestInterceptors(requestInterceptors.values()); builder.requestInterceptors(requestInterceptors.values());
} }
......
...@@ -45,6 +45,7 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients; ...@@ -45,6 +45,7 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient; import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.cloud.netflix.ribbon.StaticServerList; import org.springframework.cloud.netflix.ribbon.StaticServerList;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -92,9 +93,8 @@ public class FeignClientTests { ...@@ -92,9 +93,8 @@ public class FeignClientTests {
@Autowired @Autowired
private Client feignClient; private Client feignClient;
// @FeignClient(value = "http://localhost:9876", loadbalance = false) @FeignClient(value = "localapp", configuration = TestClientConfig.class)
@FeignClient("localapp") protected interface TestClient {
protected static interface TestClient {
@RequestMapping(method = RequestMethod.GET, value = "/hello") @RequestMapping(method = RequestMethod.GET, value = "/hello")
Hello getHello(); Hello getHello();
...@@ -120,19 +120,7 @@ public class FeignClientTests { ...@@ -120,19 +120,7 @@ public class FeignClientTests {
ResponseEntity head(); ResponseEntity head();
} }
@FeignClient(serviceId = "localapp") public static class TestClientConfig {
protected static interface TestClientServiceId {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
Hello getHello();
}
@Configuration
@EnableAutoConfiguration
@RestController
@EnableFeignClients(clients = {TestClientServiceId.class, TestClient.class},
defaultConfiguration = TestDefaultFeignConfig.class)
@RibbonClient(name = "localapp", configuration = LocalRibbonClientConfiguration.class)
protected static class Application {
@Bean @Bean
public RequestInterceptor interceptor1() { public RequestInterceptor interceptor1() {
...@@ -153,6 +141,25 @@ public class FeignClientTests { ...@@ -153,6 +141,25 @@ public class FeignClientTests {
} }
}; };
} }
}
@FeignClient(name = "localapp1")
protected interface TestClientServiceId {
@RequestMapping(method = RequestMethod.GET, value = "/hello")
Hello getHello();
}
@Configuration
@EnableAutoConfiguration
@RestController
@EnableFeignClients(clients = {TestClientServiceId.class, TestClient.class},
defaultConfiguration = TestDefaultFeignConfig.class)
@RibbonClients({
@RibbonClient(name = "localapp", configuration = LocalRibbonClientConfiguration.class),
@RibbonClient(name = "localapp1", configuration = LocalRibbonClientConfiguration.class)
})
protected static class Application {
@RequestMapping(method = RequestMethod.GET, value = "/hello") @RequestMapping(method = RequestMethod.GET, value = "/hello")
public Hello getHello() { public Hello getHello() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment