Spring Multiple Feign Clients with different configuration

135 Views Asked by At

So far I have always used FeignClient via annotation @FeignClient and @EnableFeignClients and set the configurations there so that the beans are scoped for the client. If I understand it correctly, the beans are not available for the entire application but only for the client.

Now I have the use case of building some Feign clients dynamically. The FeignBuilder is used for this.

Currently this is simply done via direct configuration and the FeignBuilder. However, the beans are now fully available and not just for the client.

Now I would be interested in how the @EnableFeignClient annotation does this so that the beans are only available for this FeignBuilder or Feign Client.

For example, how do I have to build a Feign with a custom interceptor so that this interceptor is not available for the entire application.

It currently looks like this. Which is of course wrong, since all the beans are available within the application.

   @Import( { FeignClientsConfiguration.class } )
   public class MyFeignConfiguration {



      @Bean
      Feign myClientFeign( RequestInterceptor interceptor ) {

         return new Feign.Builder()
               .encoder( etc. )
               .queryMapEncoder( new QueryModelMapEncoder() )
               .decoder( decoder )
               .errorDecoder( apiClientErrorDecoder )
               .client( new OkHttpClient() )
               .contract( new SpringMvcContract() )
               .requestInterceptor( requestInterceptor )
               .build();
      }


   }
0

There are 0 best solutions below