国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

SpringCloud Feign的使用代碼實例

瀏覽:38日期: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
相關文章:
主站蜘蛛池模板: 黄网站在线播放视频免费观看 | aaa免费毛片| 欧美成人午夜在线全部免费 | 成 人 a v免费视频 | 99精品视频在线播放2 | 国产成人欧美视频在线 | 日韩av线上 | 中国女人毛片 | 国产成人一区二区三区免费观看 | 大尺度福利视频在线观看网址 | 国产福利拍拍拍 | 亚欧成人一区二区 | 在线aaa| 欧美一区二区三区视视频 | 久久影院国产 | 亚洲精品中文一区不卡 | 久久99久久精品国产只有 | 九九精品激情在线视频 | 精品久久中文字幕有码 | 欧美一级专区免费大片 | 欧美一级香蕉毛片 | 性欧美另类老妇高清 | 欧美日韩午夜视频 | 91成年人 | 久久久www免费人成看片 | 人人公开免费超级碰碰碰视频 | 成年日韩片av在线网站 | 色拍拍在精品视频69影院在线 | 9久9久女女热精品视频免费观看 | 久久亚洲国产精品一区二区 | 久久99视频免费 | 亚洲国产成人私人影院 | 性刺激免费视频观看在线观看 | 国产欧美一区二区三区沐欲 | 99精品在线免费 | 99视频在线免费观看 | 亚洲成人黄色在线 | 成人全黄三级视频在线观看 | av成人天堂| 久青草国产手机在线观 | 精品视频在线免费播放 |