一、引言

什么是Feign

  Feign远程调用,核心就是通过一系列的封装和处理,以JAVA注解的方式定义的远程调用API接口,最终转换成HTTP的请求形式。然后将HTTP的请求的响应结果,解析成JAVA Bean,返回给调用方,实现远程接口调用

  Feign个人理解实际上是一种对RPC远程过程调用的一种实现,通过注解可以很方便的去进行RPC调用,减少配置。

二、Feign调用实例

  我们需要创建2个工程:order-server、gds-server,然后分别在其中定义出controller来模拟订单系统调用商品系统的业务流程。

gds-server

pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <groupId>com.zhbf</groupId>
 6     <artifactId>gds-server</artifactId>
 7     <version>0.0.1-SNAPSHOT</version>
 8     <name>gds-server</name>
 9     <description>商品服务【有梦想的肥宅】</description>
10 
11     <parent>
12         <groupId>org.springframework.boot</groupId>
13         <artifactId>spring-boot-starter-parent</artifactId>
14         <version>1.5.6.RELEASE</version>
15         <relativePath/>
16     </parent>
17 
18     <properties>
19         <java.version>1.8</java.version>
20         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
22         <spring-boot.version>1.5.6.RELEASE</spring-boot.version><!--Spring Boot版本-->
23         <spring-cloud.version>1.4.6.RELEASE</spring-cloud.version><!--Spring Cloud版本-->
24     </properties>
25 
26     <dependencyManagement>
27         <dependencies>
28             <!--指定下载源和使用Spring Boot的版本-->
29             <dependency>
30                 <groupId>org.springframework.boot</groupId>
31                 <artifactId>spring-boot-dependencies</artifactId>
32                 <version>${spring-boot.version}</version>
33                 <type>pom</type>
34                 <scope>import</scope>
35             </dependency>
36             <!--指定下载源和使用Spring Cloud的版本-->
37             <dependency>
38                 <groupId>org.springframework.cloud</groupId>
39                 <artifactId>spring-cloud-dependencies</artifactId>
40                 <version>Edgware.SR5</version>
41                 <type>pom</type>
42                 <scope>import</scope>
43             </dependency>
44         </dependencies>
45     </dependencyManagement>
46 
47 
48     <dependencies>
49         <!--引入Spring Boot依赖-->
50         <dependency>
51             <groupId>org.springframework.boot</groupId>
52             <artifactId>spring-boot-starter</artifactId>
53         </dependency>
54         <!--引入lombok-->
55         <dependency>
56             <groupId>org.projectlombok</groupId>
57             <artifactId>lombok</artifactId>
58             <optional>true</optional>
59         </dependency>
60         <!--引入Spring Cloud的Eureka依赖-->
61         <dependency>
62             <groupId>org.springframework.cloud</groupId>
63             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
64             <version>${spring-cloud.version}</version>
65         </dependency>
66         <!--引入fastjson依赖-->
67         <dependency>
68             <groupId>com.alibaba</groupId>
69             <artifactId>fastjson</artifactId>
70             <version>1.2.76</version>
71         </dependency>
72         <!--服务调用-->
73         <dependency>
74             <groupId>org.springframework.cloud</groupId>
75             <artifactId>spring-cloud-starter-openfeign</artifactId>
76         </dependency>
77     </dependencies>
78 
79 </project>
View Code

相关文章:

  • 2019-05-28
  • 2021-04-04
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
猜你喜欢
  • 2020-02-24
  • 2022-12-23
  • 2021-05-18
  • 2021-07-05
  • 2021-07-05
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案