OpenFeign 教程: 使用 Spring Cloud Alibaba 和 Nacos
warning:
这篇文章距离上次修改已过418天,其中的内容可能已经有所变动。
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = "user-service", url = "http://localhost:8081")
public interface UserServiceFeignClient {
@GetMapping("/user")
String getUser(@RequestParam(name = "id") String id);
}这个示例代码定义了一个UserServiceFeignClient接口,使用@FeignClient注解指定了服务名称和基础URL。接口中的getUser方法使用@GetMapping注解定义了一个HTTP GET请求的映射,其中包含了请求参数。这个接口可以被Spring的代理类实现,用于远程调用user-service服务的/user接口。
评论已关闭