How to configure the “name” and “url” annotations in FeignClient?

When using FeignClient, configuration can be done through the name and URL annotations.

  1. What is your name?
@FeignClient(name = "example-service")
public interface ExampleServiceClient {
    // ...
}

The ‘name’ attribute here specifies the name of the FeignClient, the name can be any string used to identify different FeignClients.

  1. website address
@FeignClient(url = "http://example.com")
public interface ExampleServiceClient {
    // ...
}

The “url” property here specifies the service URL of the FeignClient, which can be any valid URL string.

It is important to note that the name and url annotations are mutually exclusive, only one of them can be used. If both name and url annotations are used at the same time, an exception will be thrown.

Furthermore, the @Name annotation can also be used in conjunction with the Eureka service registry, for example:

@FeignClient(name = "example-service", fallback = ExampleServiceClientFallback.class)
public interface ExampleServiceClient {
    // ...
}

The fallback attribute here specifies the fallback class for the FeignClient to handle cases of request failure.

bannerAds