I have several Feign clients, with different configurations. The common config looks like the following
public class FeignLogConfig {
@Bean
public LogOkHttpInterceptor LogOkHttpInterceptor() { //custom interceptor
return new LogOkHttpInterceptor();
}
@Bean
public feign.okhttp.OkHttpClient okHttpClient(LogOkHttpInterceptor interceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(interceptor);
return new feign.okhttp.OkHttpClient(builder.build());
}
}
that can be further extended
public class FeignRetryerConfig extends FeignLogConfig {
@Bean
public Retryer retryer() {
return new Retryer.Default(100, 500, 5);
}
}
or simply
public class FeignEmptyConfig extends FeignLogConfig {}
A client annotated with
@FeignClient(value = "retryClient", url = url, configuration = FeignRetryerConfig.class)
or
@FeignClient(value = "logClient", url = url, configuration = FeignLogConfig.class)
will actually use the defined interceptor, yet
@FeignClient(value = "emptyClient", url = url, configuration = FeignEmptyConfig.class)
would not use the LogOkHttpInterceptor
. I can't find an explanation on the documentation, so I don't know if I'm actually missing something.
A minimal example can be found here.
EDIT: to me, at the moment, seems not related to Feign, but to how Spring aggregates the configurations. While the above FeignEmptyConfig
doesn't work, the following does work!
@Import(CommonFeignConfig.class)
public class EmptyFeignConfig {}