欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud使用Feign實(shí)現(xiàn)動態(tài)路由操作

 更新時間:2022年06月02日 17:01:43   作者:寫程序的小王叔叔  
這篇文章主要介紹了SpringCloud使用Feign實(shí)現(xiàn)動態(tài)路由操作,文章圍繞主題展開詳細(xì)的內(nèi)容介紹具有一定的參考價值,需要的小伙伴可以參考一下

一、理解及原理

1.1理解

Feign
基于接口 + 注解的方式,一個http請求調(diào)用的輕量級框架

Feign是Netflix開發(fā)的聲明式、模板化的HTTP客戶端, Feign可以幫助我們更快捷、優(yōu)雅地調(diào)用HTTP API。

Feign是一種聲明式、模板化的HTTP客戶端(僅在Application Client中使用)。聲明式調(diào)用是指,就像調(diào)用本地方法一樣調(diào)用遠(yuǎn)程方法,無需感知操作遠(yuǎn)程http請求

1.2原理

二、Feign搭建實(shí)現(xiàn)步驟

  • 創(chuàng)建Springboot基礎(chǔ)項目
  • 在注冊中心(Eureka)配置的基礎(chǔ)上,進(jìn)行配置Feign

三、配置文件(pom.xml)

基礎(chǔ)配置:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

整體:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.8.7</version>
</dependency>
<!--添加lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--pagehelper分頁-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

<!--驗(yàn)證碼https://blog.csdn.net/qq_41853447/article/details/105893567-->
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
<!--security權(quán)限管理-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

</dependencies>

四、程序代碼

在啟動類上加上@EnableFeignClients,開啟Feign的應(yīng)用

@EnableEurekaServer
@EnableSwagger2
@SpringBootApplication
@EnableFeignClients(basePackages = "com.personal.pserver")
public class PserverApplication {

public static void main(String[] args) {
SpringApplication.run(PserverApplication.class, args);
System.out.println("========================person-server已啟動========================");
}

}

啟動類添加完成之后,在指定需要訪問的service注冊使用,

見其他博主講解:

在通過Feign來實(shí)現(xiàn)遠(yuǎn)程服務(wù)調(diào)用時,需要提供一個本地接口來繼承服務(wù)標(biāo)準(zhǔn)工程提供的服務(wù)接口。這個本地接口不需要給予任何實(shí)現(xiàn),在底層Spring容器會為這個接口提供一個基于JDK實(shí)現(xiàn)的代理對象,這個代理對象由Feign技術(shù)提供具體的HandlerInterceptor邏輯,實(shí)現(xiàn)遠(yuǎn)程的調(diào)用。實(shí)現(xiàn)過程類似通過代碼調(diào)用LoadBalancerClient實(shí)現(xiàn)的Rest遠(yuǎn)程訪問。
  而本地接口繼承服務(wù)標(biāo)準(zhǔn)接口后,需要提供注解@FeignClient,注解的屬性name代表當(dāng)前接口要調(diào)用的遠(yuǎn)程服務(wù)的應(yīng)用命名。

@RestController
@Api(tags = "平臺基本信息管理")
@RequestMapping("/v1/pserver/platform/manager")
public class PlatformController {

@Autowired
private PPlatformService platformService;

@ApiOperation(value = "獲取平臺基本信息", notes = "獲取平臺基本信息", httpMethod = "GET")
@RequestMapping(value = "/findPlatformInfo",method = RequestMethod.GET)
public PPlatform findPlatformInfo(@RequestParam("platformId") String platformId) {
PPlatform pPlatform = platformService.findOnePlatformById(platformId);
return pPlatform;
}
}
@FeignClient(name="p-platform-service")
public interface PPlatformService {

/***
* 獲取平臺基本信息
* @param platformId
* @return
*/
@RequestMapping(value="/findPlatformInfo",method = RequestMethod.GET)
PPlatform findOnePlatformById(@RequestParam(value="platformId") String platformId);

}

五、結(jié)果演示

到此這篇關(guān)于SpringCloud使用Feign實(shí)現(xiàn)動態(tài)路由操作的文章就介紹到這了,更多相關(guān)Feign動態(tài)路由內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring-Boot中如何使用多線程處理任務(wù)方法

    Spring-Boot中如何使用多線程處理任務(wù)方法

    這篇文章主要介紹了Spring-Boot中如何使用多線程處理任務(wù)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • Java的Spring框架的三種連接池的基本用法示例

    Java的Spring框架的三種連接池的基本用法示例

    這篇文章主要介紹了Java的Spring框架的三種連接池的基本用法示例,Spring框架是Java下注明的SSH三大web開發(fā)框架之一,需要的朋友可以參考下
    2015-11-11
  • Java定時清理過期文件的實(shí)例代碼

    Java定時清理過期文件的實(shí)例代碼

    這篇文章主要介紹了Java定時清理過期文件的實(shí)例代碼,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2018-12-12
  • java反射獲取和調(diào)用方法

    java反射獲取和調(diào)用方法

    本篇內(nèi)容主要給大家詳細(xì)講解了java反射獲取方法以及調(diào)用方法,需要的朋友參考學(xué)習(xí)一下吧。
    2017-12-12
  • 使用Nexus搭建Maven私服教程的方法步驟

    使用Nexus搭建Maven私服教程的方法步驟

    本文主要介紹了使用Nexus搭建Maven私服教程的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • 詳解Java中字典樹(Trie樹)的圖解與實(shí)現(xiàn)

    詳解Java中字典樹(Trie樹)的圖解與實(shí)現(xiàn)

    Trie又稱為前綴樹或字典樹,是一種有序樹,它是一種專門用來處理串匹配的數(shù)據(jù)結(jié)構(gòu)。本文將利用圖解詳細(xì)講解Trie樹的實(shí)現(xiàn),需要的可以參考一下
    2022-05-05
  • SpringBoot整合Pulsar的實(shí)現(xiàn)示例

    SpringBoot整合Pulsar的實(shí)現(xiàn)示例

    本文主要介紹了SpringBoot整合Pulsar的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • 如何利用JAVA實(shí)現(xiàn)走迷宮程序

    如何利用JAVA實(shí)現(xiàn)走迷宮程序

    最近經(jīng)常在機(jī)房看同學(xué)在玩一個走迷宮的游戲,比較有趣,自己也用java實(shí)現(xiàn)了一個,這篇文章主要給大家介紹了關(guān)于如何利用JAVA實(shí)現(xiàn)走迷宮程序的相關(guān)資料,需要的朋友可以參考下
    2021-06-06
  • Java反轉(zhuǎn)字符串的10種方法

    Java反轉(zhuǎn)字符串的10種方法

    這篇文章主要介紹了Java反轉(zhuǎn)字符串的10種方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,下面我們來一起學(xué)習(xí)一下吧
    2019-06-06
  • Java 實(shí)現(xiàn)repalceAll只替換第二個匹配到的字符串

    Java 實(shí)現(xiàn)repalceAll只替換第二個匹配到的字符串

    這篇文章主要介紹了Java 實(shí)現(xiàn)repalceAll只替換第二個匹配到的字符串,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12

最新評論