3

I have a whole bunch of Feign clients that uses a shared configuration(MyFeignConfiguration.class):

@FeignClient(name = "clientA", url = "http://serviceA.com", fallbackFactory = ServiceAFallbackFactory.class, configuration = MyFeignConfiguration.class)

@FeignClient(name = "clientB", url = "http://serviceB.com", fallbackFactory = ServiceBFallbackFactory.class, configuration = MyFeignConfiguration.class)

@FeignClient(name = "clientC", url = "http://serviceC.com", fallbackFactory = ServiceCFallbackFactory.class, configuration = MyFeignConfiguration.class)

However, for a new client, I want to change the underlying Http Client that is used to OkHttp one. In the MyFeignConfiguration class, I can add the following:

@Configuration
class MyFeignConfiguration {
    @Bean
    public Client getClient() {
        return OkHttpClient() // use the OkHttp client 
    }
   
    @Bean
    public ErrorDecoder getErrorDecoder() {
        //... existing configs
    }

However, now all of the clients are using this OkHttp client. How do configure the new feign client so that only it is using the OkHttp client? Also, I still need to use the existing default configs(like the ErrorDecoder) from my main MyFeignConfiguration class.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
HelloWorld
  • 109
  • 2
  • 9

2 Answers2

3

looking at the doc there is a imported Note https://cloud.spring.io/spring-cloud-openfeign/reference/html/#spring-cloud-feign-overriding-defaults

FooConfiguration does not need to be annotated with @Configuration. However, if it is, then take care to exclude it from any @ComponentScan that would otherwise include this configuration as it will become the default source for feign.Decoder, feign.Encoder, feign.Contract, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any @ComponentScan or @SpringBootApplication, or it can be explicitly excluded in @ComponentScan.

Try to remove the annotation: @Configuration

0

You have to create new FeignConfiguration class for your new Feign client, Also you should remove the @Configuration from your Feign configuration classes.