【feign】使用Feign的方式访问Zuul网关 和 gateway网关

前言

使用Feign的方式访问Zuul网关

文档:http://eimsteim.github.io/2018/04/24/%E4%BD%BF%

使用Feign的方式访问gateway网关

文档:https://blog.csdn.net/qq_28114159/article/details/107231866
服务端配置方式:

  1. @FeignClient的name为gateway网关服务名称
  2. @FeignClient的path为当前服务的名称
  3. @FeignClient的contextId随便起一个,当前服务下不能重复

网关配置方式:

# gateway相关
## spring.cloud.gateway.discovery.locator.enabled:true/false 启用基于服务发现的路由定位,如果开启,则默认会去除第一段地址。
## spring.cloud.gateway.discovery.locator.lowerCaseServiceId:启用服务实例id名称小写支持
## spring.cloud.gateway.loadbalancer.use404 找不到时返回404
## spring.cloud.gateway.routes:路由
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true
spring.cloud.gateway.loadbalancer.use404=true

其他的就不需要了,我这边只是测试的时候添加了一个TokenFilter。
下面开始请求:
postman
在这里插入图片描述
web端
在这里插入图片描述
gateway
在这里插入图片描述
这是配置,里面没有配置相关路由
在这里插入图片描述
这是服务端
在这里插入图片描述
完成!!!

理解

首先看到了zuul的这篇文章,知道了它的请求过程。
然后又找到了gateway的这篇文章,测试了下,发现没有成功。下面是它的截图:
在这里插入图片描述
它里面没有设置path。 后来我加上了path,就好了。

猜你喜欢

转载自blog.csdn.net/s1441101265/article/details/112245582