【Spring Cloud】 Feign 客户端的使用与配置
    		       		warning:
    		            这篇文章距离上次修改已过422天,其中的内容可能已经有所变动。
    		        
        		                
                
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
 
@FeignClient(name = "example-service", url = "http://localhost:8080")
public interface ExampleServiceClient {
 
    @GetMapping("/data")
    String getData(@RequestParam(value = "param") String param);
}这个示例代码定义了一个Feign客户端接口ExampleServiceClient,用于访问example-service服务的/data端点。通过@FeignClient注解指定服务名称和基础URL。getData方法使用@GetMapping注解来声明HTTP GET方法和请求的端点路径,并且通过@RequestParam注解来声明传递给端点的参数。这个客户端接口可以被Spring应用的其他组件注入并使用,以简化服务间的调用。
评论已关闭