赞
踩
目录
1.新建项目springcloud-feign-consumer
父项目版本详见:https://blog.csdn.net/bfss_11/article/details/119056522
涉及到的文件:
spring-cloud-starter-netflix-eureka-client
spring-cloud-starter-openfeign
版本在父项目中统一管理
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-openfeign</artifactId>
- </dependency>
端口为9320。application.name=springcloud-consumer,和springcloud-consumer项目一样
- spring:
- application:
- name: springcloud-consumer
-
- server:
- port: 9320
-
- eureka:
- instance:
- instance-id: springcloud-feign-consumer
- appname: ${spring.application.name}
- prefer-ip-address: true
- lease-renewal-interval-in-seconds: 5
- lease-expiration-duration-in-seconds: 5
- client:
- service-url:
- defaultZone: http://test1:9110/eureka/,http://test2:9120/eureka/
@EnableFeignClients
@EnableEurekaClient
CommonFeignService为使用feign代理的接口
使用@FeignClient,springcloud-common为需要进行代理的服务名称,和注册在eureka中的appname一致。
接口定义需要和被代理的接口完全一致。入参、返回值、@RequestBody、@RequestParm等
访问http://localhost:9320/feignConsumer/get
返回9230,说明调用了springcloud-common3服务
切换方式和前一章ribbon使用方式一致。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。