adroit
adroit

Reputation: 31

Feign Client with annotation

I am trying to use feign client with annotation @FeignClient. And i want to invoke feignClient method manually. It works fine when I build feignclient manually with Feign.Builder. But I am a bit lost in using @FeignClient annotation.

Thanks, Khush

Upvotes: 1

Views: 1195

Answers (1)

Saurabh Oza
Saurabh Oza

Reputation: 179

Feign.Builder - is used when you want to create the fiegn client manually.

Example :

@Import(FeignClientsConfiguration.class)
class FooController {

    private FooClient fooClient;

    private FooClient adminClient;

    @Autowired
    public FooController(
            ResponseEntityDecoder decoder, SpringEncoder encoder, Client client) {
        this.fooClient = Feign.builder().client(client)
                .encoder(encoder)
                .decoder(decoder)
                .requestInterceptor(new BasicAuthRequestInterceptor("user", "user"))
                .target(FooClient.class, "http://PROD-SVC");
        this.adminClient = Feign.builder().client(client)
                .encoder(encoder)
                .decoder(decoder)
                .requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
                .target(FooClient.class, "http://PROD-SVC");
    }
}

@FeignClient - Its used when you just define the method declarations in an interface and spring takes care of creating a builder for you on server start up.

@FeignClient("stores")
public interface StoreClient {
    @RequestMapping(method = RequestMethod.GET, value = "/stores")
    List<Store> getStores();

    @RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
    Store update(@PathVariable("storeId") Long storeId, Store store);
}

Upvotes: 1

Related Questions