软件编程
位置:首页>> 软件编程>> java编程>> Spring Cloud Gateway去掉url前缀

Spring Cloud Gateway去掉url前缀

作者:草宝虫  发布时间:2023-06-05 00:54:38 

标签:SpringCloud,Gateway,url前缀

Spring Cloud Gateway去掉url前缀

主要是增加一个 route,其他配置不变


routes:
 - id: service_customer
   uri: lb://CONSUMER
   order: 0
   predicates:
     - Path=/customer/**
   filters:
     - StripPrefix=1
     - AddResponseHeader=X-Response-Default-Foo, Default-Bar

新增的StripPrefix可以接受一个非负整数,对应的具体实现是StripPrefixGatewayFilterFactory,从名字就可以看出它的作用是去掉前缀的,那个整数即对应层数。

具体到本例中,我们通过 Spring Cloud Gateway 访问 /customer/hello/windmt,那么当网关服务向后转发请求时,会去掉/customer,微服务收到的就是/hello/windmt。

Spring Cloud中eureka.instance为前缀的的常用配置参数说明

参数名说明默认值
preferIpAddress是否优先使用IP地址作为主机名的标识false
leaseRenewalIntervalInSecondsEureka客户端向服务端发送心跳的时间间隔,单位为秒30
leaseExpirationDurationInSecondsEureka服务端在收到最后一次心跳之后等待的时间上限,单位为秒。超过该时间之后服务端会将该服务实例从服务清单中剔除,从而禁止服务调用请求被发送到该示例上90
nonSecurePort非安全的通信端口号80
securePort安全的通信端口号443
nonSecurePortEnabled是否启用非安全的通信端口号true
securePortEnabled是否启用安全的通信端口号
appname服务名,默认取spring.application.name的配置值unkonwn
hostname主机名,不配置的时候将根据操作系统的主机名来获取

注意:


org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean

类中,可以查看各个参数的默认值。

来源:https://wanghq.blog.csdn.net/article/details/85336282

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com