av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

SpringCloud Feign的使用代碼實(shí)例

瀏覽:70日期:2023-09-16 15:09:42

1.官方文檔

https://cloud.spring.io/spring-cloud-static/spring-cloud-openfeign/2.2.2.RELEASE/reference/html/

2.添加依賴

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

3.添加啟動(dòng)類注解

import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.openfeign.EnableFeignClients;@SpringBootApplication//@MapperScan('cn.ytheng.order_service')@EnableFeignClientspublic class OrderServiceApplication { public static void main(String[] args) { SpringApplication.run(OrderServiceApplication.class, args); }}

4.添加Feign接口

import org.springframework.cloud.openfeign.FeignClient;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;/** * * 商品服務(wù)客戶端 * product-service: 調(diào)用服務(wù)名稱,即spring.application.name * */@FeignClient(name = 'product-service')public interface ProductClient { @GetMapping('/api/v1/product/find') String getById(@RequestParam('id') int id);}

5.添加Controller

import cn.theng.order_service.service.ProductClient;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping('/api/v1/order')public class ProductOrderController { @Autowired private ProductClient productClient; @PostMapping('/test2') public Object test2(@RequestParam('product_id') int productId) { String product = productClient.getById(productId); return 'success'; }}

6.添加application.yml配置

server: port: 8781eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/spring: application: name: order-service#設(shè)置調(diào)用服務(wù)超時(shí)時(shí)間#product-service為服務(wù)名稱,也可以設(shè)置為默認(rèn)值defaultfeign: client: config: product-service: connectTimeout: 5000 readTimeout: 11000

7.訪問地址

SpringCloud Feign的使用代碼實(shí)例

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 国产午夜精品一区二区三区视频 | 国产美女一区二区三区 | 午夜网站在线观看 | 国产精品久久久久久无人区 | 天天色网站| 一区二区三区毛片 | 日韩二三区 | 香蕉视频色版 | 欧美在线视频免费 | 日韩久久久 | 青青草视频污 | 国产男女无遮挡猛进猛出 | 俺去俺来也在线www色官网 | 美女网站视频在线观看 | 久久久久成人网 | 亚洲不卡 | av在线小说| 亚洲理论片| 4438成人网 | 亚洲一区二区在线免费观看 | 日韩av成人在线 | 久久午夜视频 | 三上悠亚一区二区 | 人人干人人爽 | 国产毛片毛片 | 在线网站免费观看18 | 久久精品日韩 | 98久久| www.成人| 香蕉视频一区二区 | 亚洲综合区 | 日韩欧美在线一区 | 亚洲一区视频在线 | 欧美国产一区二区 | 97色在线| 91在线看片 | 日韩在线观看中文字幕 | 日韩免费视频一区二区 | 欧美日韩三区 | 久久久久久久久久久久久久久久久久久 | 在线观看网址你懂的 |