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 = Feign.builder().client(client) .encoder(encoder) .decoder(decoder) .contract(contract) .requestInterceptor(new BasicAuthRequestInterceptor("admin",
"admin")) .target(AccountService.class, "http://ACCOUNT-SERVICE"); } }
We have created two Feign clients of the AccountService type, cutomerAccountService and adminAccountService, using the Feign Builder API.