前言
本文介紹如何使用fegin 調(diào)用服務(wù)。
操作步驟
- 添加fegin依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
應(yīng)用啟動(dòng)類加注解
@EnableFeignClients
聲明feign相關(guān)接口
@FeignClient(name = "product")
public interface ProductClient {
@GetMapping("/msg") //訪問(wèn)product下面msg這個(gè)接口
String productMsg();
}
- 調(diào)用訪問(wèn)服務(wù)
public class ClientController {
@Autowired
private ProductClient productClient;
@GetMapping("/getProductMsg")
public String getProductMsg() {
String response = productClient.productMsg();
log.info("resoponse={}", response);
return response;
}
}