色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

SpringCloud Feign的使用代碼實例

瀏覽:56日期: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
相關文章:
主站蜘蛛池模板: 亚洲天堂视频一区 | 日本高清福利视频在线观看 | 国产一区二区三区在线观看免费 | 欧美a级毛片 | 日韩欧美一级毛片在线 | 日韩欧美视频在线播放 | 欧美一区二区三区免费 | 久久99国产精品久久99果冻传媒 | 国内视频一区二区 | 午夜三级在线 | 亚洲一级毛片在线播放 | 久久精品亚洲 | 纯欧美一级毛片免费 | 在线中文字幕播放 | 国产精品亚洲高清一区二区 | 国产成人深夜福利短视频99 | 日韩日韩日韩手机看片自拍 | 奇米5555 | 一区高清 | 国产精品久久久久三级 | 996热在线视频 | 免费观看欧美成人h | 高清精品女厕在线观看 | 午夜私人影院免费体验区 | aaaaaa级特色特黄的毛片 | 日日摸天天摸狠狠摸视频 | 韩国一级永久免费观看网址 | 日韩在线不卡一区在线观看 | 自拍视频在线观看 | 毛片久久 | 国产成人精品亚洲777图片 | 国产午夜亚洲精品理论片不卡 | 玖草视频在线观看 | 国产精品久久久久亚洲 | 日韩中文字幕视频 | 亚洲系列 | 精品国语_高清国语自产 | 国产一区a | 一个人免费观看日本www视频 | 亚洲国产在 | 国产一级做a爰片久久毛片 国产一级做a爰片久久毛片99 |