前言
本文介绍如何使用fegin 调用服务。
操作步骤
- 添加fegin依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
应用启动类加注解
@EnableFeignClients
声明feign相关接口
@FeignClient(name = "product")
public interface ProductClient {
@GetMapping("/msg") //访问product下面msg这个接口
String productMsg();
}
- 调用访问服务
public class ClientController {
@Autowired
private ProductClient productClient;
@GetMapping("/getProductMsg")
public String getProductMsg() {
String response = productClient.productMsg();
log.info("resoponse={}", response);
return response;
}
}