午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

SpringCloud Feign的使用代碼實例

瀏覽:126日期: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.添加啟動類注解

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;/** * * 商品服務客戶端 * product-service: 調用服務名稱,即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#設置調用服務超時時間#product-service為服務名稱,也可以設置為默認值defaultfeign: client: config: product-service: connectTimeout: 5000 readTimeout: 11000

7.訪問地址

SpringCloud Feign的使用代碼實例

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 99视频网| 自拍偷拍视频在线观看 | 欧美亚洲一区二区三区四区 | 亚色在线观看 | av一二 | 毛片黄色片| 国产日韩在线观看一区 | 欧美日韩在线国产 | 69福利区 | 400部精品国偷自产在线观看 | 欧美日韩有码 | 一级欧美视频 | 成年人在线免费观看视频网站 | 警花观音坐莲激情销魂小说 | 一区二区三区视频免费在线观看 | 欧美a一级 | 欧美一区二区三区激情视频 | 欧美精品123 | 五月天综合激情网 | 国产精品久久久久久久久久久久午夜片 | 日产精品久久久一区二区 | 国产黄色精品网站 | 在线观看欧美日韩视频 | 午夜黄色剧场 | 国产麻豆91| 国产欧美一区二区三区四区 | 国产不卡在线 | 大香蕉毛片 | 最好看的2019年中文在线观看 | 成人在线免费观看视频 | 97综合视频 | 欧美在线视频二区 | 欧美高清一区 | 欧美成人一区二区三区片免费 | 久久中文av| 欧美资源在线 | 99视频一区二区 | 国产视频福利 | 久久久久久久久久免费视频 | 成人久久视频 | 毛片免 |