亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:35日期: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.訪問(wèn)地址

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

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 美国一级特黄aa大片 | 国产一区二区fc2ppv在线播放 | 国产一级特黄高清免费大片 | 亚洲精品免费在线 | 成人性色生活片免费看爆迷你 | 美国黄色一级片 | 尤物精品 | a级毛片在线免费观看 | 成人特级毛片 | 成人黄色片在线观看 | 国产成人精品在视频 | 亚洲v欧美v日韩v国产v | 高清一区在线 | 免费观看黄色大片 | 日本成人一级 | 国产亚洲青色国产 | 国产精品视频久久久久 | 国产不卡在线播放 | 精品一区二区三区在线视频 | 日日麻批 | 黄色一级毛片免费 | 视频在线观看一区二区 | 亚洲欧美日韩一级特黄在线 | 久久综合精品国产一区二区三区 | 激情亚洲 | 国产免费又色又爽视频 | 久久精品国产国产精品四凭 | 999www人成免费视频 | 国内精品综合九九久久精品 | 床上毛片 | 91久久精品日日躁夜夜躁欧美 | 黄色的视频免费 | 一级爱做片免费观看久久 | 午夜国产高清精品一区免费 | 国产精品日产三级在线观看 | 国内精品自在自线在免费 | 国产乳摇福利视频在线观看 | 中文字幕国产日韩 | 成人18在线观看 | 免费看黄色三级毛片 | 青青青视频自偷自拍视频1 青青青视频免费一区二区 青青青视频蜜桃一区二区 青青青爽国产在线视频 |