声明式远程调用OpenFeign(微服务调用微服务)
通过注册中心nacos进行远程调用
如何远程调用别的服务
1引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2编写一个调用远程的接口,给springcloud,在接口中编写需要调用远程服务的某某请求
3开启feign远程调用功能@EnableFeignClients
4. 别的服务
报错,缺loadbalancer
Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
参考
https://blog.csdn.net/weixin_45729934/article/details/110310119
会员服务
Did you forget to include spring-cloud-starter-loadbalancer?
spring cloud版本过高之后,没有包含负载均衡的包
测试代码
最终会员微服务 调用 优惠券服务 远程调用成功
{"msg":"success","code":0,
"优惠券":[{"id":null,"couponType":null,"couponImg":null,"couponName":"满100减50","num":null,"amount":null,"perLimit":null,"minPoint":null,"startTime":null,
"endTime":null,"useType":null,"note":null,"publishCount":null,"useCount":null,"receiveCount":null,"enableStartTime":null,"enableEndTime":null,"code":null,
"memberLevel":null,"publish":null}],
"member":{"id":null,"levelId":null,"username":null,"password":null,"nickname":"塔吉克","mobile":null,"email":null,"header":null,"gender":null,"birth":null,
"city":null,"job":null,"sign":null,"sourceType":null,"integration":null,"growth":null,"status":null,"createTime":null}}