第一步添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
第二步:启动类上新增注解
@EnableFeignClients
第三步:新增ProductClient接口内容如下:
//设置访问服务名product
@FeignClient(name = "product")
public interface ProductClient {
@GetMapping("/msg") //表示访问的服务下的接口名msg
String productMsg();
}
第四步:调用服务
@Autowired
private ProductClient productClient;
@GetMapping("getProductMsg")
public String getProductMsg() {
String response = productClient.productMsg();
log.info("response={}",response);
return response;
}