Springcloud基于OpenFeign實(shí)現(xiàn)服務(wù)調(diào)用代碼實(shí)例
更新時(shí)間:2020年08月19日 11:30:40 作者:陶海軍
這篇文章主要介紹了Springcloud基于OpenFeign實(shí)現(xiàn)服務(wù)調(diào)用代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
1.依賴
<!--引入open feign依賴--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> </dependencies>
2.啟動(dòng)注解
@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.服務(wù)調(diào)用
@Autowired private ProductClient productClient; @RequestMapping("/user/showProductMsg") public Map showProductMsg() { Map msg = productClient.findAll(); return msg; }
5.超時(shí)設(shè)置
feign.client.config.default.connectTimeout=5000 #配置所有服務(wù)連接超時(shí)
feign.client.config.default.readTimeout=5000 #配置所有服務(wù)等待超時(shí)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java?Stream?流中?Collectors.toMap?的用法詳解
這篇文章主要介紹了Stream?流中?Collectors.toMap?的用法,Collectors.toMap()方法是把List轉(zhuǎn)Map的操作,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01