最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年03月13日 11:30:01   作者:玉天恒  
這篇文章主要介紹了SpringCloud Feign的使用代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

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")
@EnableFeignClients
public 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: 8781
eureka:
 client:
  serviceUrl:
   defaultZone: http://localhost:8761/eureka/

spring:
 application:
  name: order-service


#設(shè)置調(diào)用服務(wù)超時(shí)時(shí)間
#product-service為服務(wù)名稱,也可以設(shè)置為默認(rèn)值default
feign:
 client:
  config:
   product-service:
    connectTimeout: 5000
    readTimeout: 11000

7.訪問(wèn)地址

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

相關(guān)文章

  • SpringBoot整合Servlet和Filter和Listener組件詳解

    SpringBoot整合Servlet和Filter和Listener組件詳解

    這篇文章主要介紹了SpringBoot整合Servlet和Filter和Listener組件詳解,在整合某報(bào)表插件時(shí)就需要使用Servlet,Spring Boot中對(duì)于整合這些基本的Web組件也提供了很好的支持,需要的朋友可以參考下
    2024-01-01
  • JavaCV使用ffmpeg實(shí)現(xiàn)錄屏功能

    JavaCV使用ffmpeg實(shí)現(xiàn)錄屏功能

    這篇文章主要介紹了JavaCV如何使用ffmpeg實(shí)現(xiàn)錄屏功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-06-06
  • 詳解java中面向?qū)ο笤O(shè)計(jì)模式類與類的關(guān)系

    詳解java中面向?qū)ο笤O(shè)計(jì)模式類與類的關(guān)系

    這篇文章主要介紹了java面向?qū)ο笤O(shè)計(jì)模式中類與類之間的關(guān)系,下面小編和大家一起來(lái)學(xué)習(xí)一下吧
    2019-05-05
  • mybatis關(guān)聯(lián)關(guān)系映射的實(shí)現(xiàn)

    mybatis關(guān)聯(lián)關(guān)系映射的實(shí)現(xiàn)

    MyBatis的關(guān)聯(lián)關(guān)系映射在復(fù)雜數(shù)據(jù)模型中至關(guān)重要,使開(kāi)發(fā)人員能夠以最靈活的方式滿足不同項(xiàng)目的需求,本文就來(lái)介紹一下mybatis關(guān)聯(lián)關(guān)系映射的實(shí)現(xiàn),感興趣的可以了解一下
    2023-09-09
  • JAVA多線程處理for循環(huán)數(shù)據(jù)詳細(xì)講解

    JAVA多線程處理for循環(huán)數(shù)據(jù)詳細(xì)講解

    這篇文章主要給大家介紹了關(guān)于JAVA多線程處理for循環(huán)數(shù)據(jù)的相關(guān)資料,我們?cè)诖a中經(jīng)常需要使用for循環(huán)這個(gè)操作來(lái)達(dá)到目的,而當(dāng)for循環(huán)的次數(shù)過(guò)多時(shí)我們會(huì)發(fā)現(xiàn)執(zhí)行效率會(huì)變的很低,整體耗時(shí)非常多,需要的朋友可以參考下
    2023-07-07
  • spring?cloud?eureka?服務(wù)啟動(dòng)失敗的原因分析及解決方法

    spring?cloud?eureka?服務(wù)啟動(dòng)失敗的原因分析及解決方法

    這篇文章主要介紹了spring?cloud?eureka?服務(wù)啟動(dòng)失敗的原因解析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • Intellij idea熱部署插件JRebel的使用

    Intellij idea熱部署插件JRebel的使用

    這篇文章主要介紹了Intellij idea熱部署插件JRebel的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • SpringBoot事務(wù)使用及回滾實(shí)現(xiàn)代碼詳解

    SpringBoot事務(wù)使用及回滾實(shí)現(xiàn)代碼詳解

    這篇文章主要介紹了SpringBoot事務(wù)使用及回滾實(shí)現(xiàn)代碼詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • springmvc實(shí)現(xiàn)跨服務(wù)器文件上傳功能

    springmvc實(shí)現(xiàn)跨服務(wù)器文件上傳功能

    這篇文章主要為大家詳細(xì)介紹了springmvc實(shí)現(xiàn)跨服務(wù)器文件上傳功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Java編程思想中關(guān)于并發(fā)的總結(jié)

    Java編程思想中關(guān)于并發(fā)的總結(jié)

    在本文中小編給大家整理的是關(guān)于Java編程思想中關(guān)于并發(fā)的總結(jié)以及相關(guān)實(shí)例內(nèi)容,需要的朋友們參考下。
    2019-09-09

最新評(píng)論

新沂市| 辽中县| 于都县| 桑日县| 灌阳县| 桐乡市| 交城县| 丰镇市| 荔浦县| 平利县| 蕉岭县| 安图县| 楚雄市| 大冶市| 新建县| 榕江县| 南丰县| 商南县| 洛浦县| 定南县| 阜宁县| 丰顺县| 潮安县| 临西县| 新野县| 瑞丽市| 彩票| 黄平县| 威海市| 昆明市| 循化| 军事| 石泉县| 曲靖市| 岱山县| 砀山县| 凉城县| 夏邑县| 武鸣县| 内丘县| 新干县|