工作原理流程图

上代码
common中添加依赖:
XML
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
创建feign的调用客户端:

java
@FeignClient("work-service") // 告诉springcloud容器,本接口为调用远程服务的service组件(声明式客户端远程调用)
public interface WorkMicroServiceFeign {
@PostMapping("/resume/init")
public GraceJSONResult init(@RequestParam("userId") String userId);
}
不通过feign也可以直接通过注册中心手动拉取列表,来进行远程调用,feign只不过帮我们封装的更好,调用更简单,简化了更多代码。

注入feign客户端并且进行微服务调用:

