- SpringCloud的服务大哥(feign组件),每一个服务之间的调用度必须需要通过feign这个大哥来发现和分配任务
- feign组件的注册声明
@FeignClient //通过这个注解来声明使用feign组件进行服务调用(前台是需要有一个eureka或zookeep等作为一个服务注册中心)
- feign组件需要添加的pom文件依赖
<-- feign组件核心jar包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<-- eureka客户端依赖jar包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
其实只需要一个jar包但是这里是需要通过eureka作为我们的服务注册与发现中心,所以需要添加一个eureka的jar包
4. 同时我们也需要在yml文件中进行一些配置(下面是yml文件中的一些配置(包括hystrix的服务容错))
server:
port: 8081
spring:
application:
name: user-provider //设置服务名称
eureka:
client:
service-url:
defaultZone: http://root:123456@localhost:8888/eureka/ //配置eureka的服务地址
feign:
hystrix:
enabled: true //开启hystrix容错
这个yml文件是在提供者(provider)中配置的,这里就对关键的进行了一下解释,对应hystrix在我的后续文章会用一篇博客专门进行说明使用的
- 到这里我们的feign组件也就说的差不多了,其他的springCloud组件在本人的博客中都会陆续更新,如有不对欢迎留言评论!