如何为特定的Spring Cloud Feign客户端排除RequestInterceptor?

New*_*bie 5 spring-cloud netflix-feign spring-cloud-feign feign spring-cloud-netflix

我有许多客户端已经定义了"全局"RequestInterceptor.对于其中一个客户,我需要排除这个"全局"拦截器.是否可以覆盖特定FeignClient的完整RequestInterceptors集?

@FeignClient(value = "foo", configuration = FooClientConfig.class)
public interface FooClient {
//operations
}

@Configuration
public class FooClientConfig{

//How do I exclude global interceptors from this client configuration?
}
Run Code Online (Sandbox Code Playgroud)

使用的spring-cloud-netflix版本为1.1.0 M5

小智 3

似乎没有简单的方法来覆盖全局拦截器。我认为你可以这样做:

@Configuration
public class FooClientConfig{

@Bean
RequestInterceptor globalRequestInterceptor() {
    return template -> {
        if (template.url().equals("/your_specific_url")) {
            //don't add global header for the specific url
            return;
        }

        //add header for the rest of requests
        template.header(AUTHORIZATION, String.format("Bearer %s", token));
    };
}
}
Run Code Online (Sandbox Code Playgroud)