Get RequestInterceptors from feign context.
Rather than pulling them from the generic context. fixes gh-683
This commit is contained in:
@@ -117,4 +117,13 @@ public class FeignClientFactory implements DisposableBean, ApplicationContextAwa
|
||||
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
|
||||
if (options != null) {
|
||||
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) {
|
||||
builder.requestInterceptors(requestInterceptors.values());
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
||||
import org.springframework.cloud.netflix.ribbon.StaticServerList;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -92,9 +93,8 @@ public class FeignClientTests {
|
||||
@Autowired
|
||||
private Client feignClient;
|
||||
|
||||
// @FeignClient(value = "http://localhost:9876", loadbalance = false)
|
||||
@FeignClient("localapp")
|
||||
protected static interface TestClient {
|
||||
@FeignClient(value = "localapp", configuration = TestClientConfig.class)
|
||||
protected interface TestClient {
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/hello")
|
||||
Hello getHello();
|
||||
|
||||
@@ -120,19 +120,7 @@ public class FeignClientTests {
|
||||
ResponseEntity head();
|
||||
}
|
||||
|
||||
@FeignClient(serviceId = "localapp")
|
||||
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 {
|
||||
public static class TestClientConfig {
|
||||
|
||||
@Bean
|
||||
public RequestInterceptor interceptor1() {
|
||||
@@ -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")
|
||||
public Hello getHello() {
|
||||
|
||||
Reference in New Issue
Block a user