zuul配置请求拦截_spring cloud Zuul 多层拦截 --- 心得

1.前言

根据教材、博客文章的实例实操,基本都是单层拦截,没有找到多层拦截的具体写法 ,让我走了很多弯路,我将其写在这里,以待以后参考。

2.环境

spring boot : 2.1.6.RELEASE

spring cloud :  Greenwich.SR2

3.准备一个端口为5001 的 Zuul网关

目录结构

导入依赖

org.springframework.cloud

spring-cloud-starter-netflix-zuul

pom文件

4.0.0

cen.cloud

cen-mycloud

0.0.1-SNAPSHOT

com.example

zuul-server-5001

0.0.1-SNAPSHOT

zuul-server-5001

Demo project for Spring Boot

1.8

org.springframework.boot

spring-boot-starter

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

org.springframework.cloud

spring-cloud-starter-netflix-zuul

org.springframework.boot

spring-boot-maven-plugin

View Code

application.properties 文件  ,设置自定义映射,路径含有/bd/则路由到 百度首页 ,用于测试

spring.application.name=zuul-server-5001server.port=5001#

eureka.client.service-url.defaultZone=http://localhost:7001/eureka/

#全局添加前缀,如 localhost:114/myzuul/test/bb ,用于识别是否需要转发路由操作

#不可使用/zuul ,猜测这是保留字

zuul.prefix=/mzuul

#//默认是false,这里是全局配置

#zuul.strip-prefix: //是否将这个代理前缀去掉

#

#忽略所有的,表示禁用默认路由,只认我们自己配置的路由.

#zuul.ignored-services="*"#

#自定义路由设置

#拦截路径

zuul.routes.bd.path=/bd/**#拦截后访问的指定地址

zuul.routes.bd.url=h

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值