SoFunction
Updated on 2025-04-07

@FeignClient's name, value, url detailed explanation

@FeignClient name, url description

name

name is used to specify the name of the current FeignClient, usually the name of the calling service.

If your application uses a service registry (such as Eureka or Consul), then name will be associated with the service name in the registry to find the corresponding service.

This parameter is required.

Example:

@FeignClient(name = "order-service")
public interface OrderClient {
    // Define interface method}

value

value and name are equivalent, and are actually an alias for name.

You can use either value or name, and they do the same.

It is generally more commonly used to express it by name.

Example:

@FeignClient(value = "order-service")
public interface OrderClient {
    // Define interface method}

url

url is used to specify the underlying URL for the request.

If your service does not use a registry but uses a static address directly, you can specify the full URL of the service through url.

Example:

@FeignClient(name = "order-client", url = "http://localhost:8080")
public interface OrderClient {
    // Define interface method}

Summarize

  • name (or value) is used to refer to the name of the service, usually used to discover services through the registry.
  • url is the URL used to directly specify the service, which is suitable for scenarios where service registration is not used.
  • When both name and url are configured, url will be effective, and Feign will directly use the address specified by url, and ignore the service registration center.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.