1.依赖
<!--引入open feign依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
2.启动注解
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class UserservicesApplication {
public static void main(String[] args) {
SpringApplication.run(UserservicesApplication.class, args);
}
}
3.接口
@FeignClient("productservices")
public interface ProductClient {
@RequestMapping("/product/findAll")
public Map findAll();
}
4.服务调用
@Autowired
private ProductClient productClient;
@RequestMapping("/user/showProductMsg")
public Map showProductMsg() {
Map msg = productClient.findAll();
return msg;
}
5.超时设置
feign.client.config.default.connectTimeout=5000 #配置所有服务连接超时
feign.client.config.default.readTimeout=5000 #配置所有服务等待超时
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。

- 本文固定链接: https://www.zxbcw.cn/post/193659/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)