Creating Feign clients

You can create your own Feign client by using Feign.builder() to configure our interface-based client. Let's see the following class, which creates two Feign clients using the same interface:

@Import(FeignClientsConfiguration.class) 
@RestController 
class CustomerController { 
   private AccountService customerAccuntService; 
   private AccountService adminAccuntService; 
 
 @Autowired 
public CustomerController( 
   Decoder decoder, Encoder encoder, Client client, Contract contract) { 
   this.customerAccuntService = Feign.builder().client(client) 
   .encoder(encoder) 
   .decoder(decoder) 
              .contract(contract) 
   .requestInterceptor(new BasicAuthRequestInterceptor("customer",  "customer")) .target(AccountService.class, "http://ACCOUNT-SERVICE"); this.adminAccuntService ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.