7

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 {}
dcolazin
  • 831
  • 1
  • 10
  • 25
  • Can you show your configuration class and your feign interface please ? – Zabon Sep 20 '22 at 11:46
  • Maybe you just need to set a constructor in the FeignEmptyConfig. – Zabon Sep 20 '22 at 12:04
  • @Zabon I added a repository where I replicate the issue; what constructor should I set in the empty config? – dcolazin Sep 20 '22 at 14:06
  • If your class extends another you have to add the super inside your constructor. But since your class doesn't have any properties, only beans, I'm not sure of what I'm saying. – Zabon Sep 20 '22 at 14:15
  • 1
    @Zabon there is a implicit super() call anyway https://stackoverflow.com/a/10508202/11478354 – dcolazin Sep 20 '22 at 14:29

0 Answers0