gateway的使用笔记

主要依赖

<!--在springboot的pom文件中,该依赖已经集成了springMVC等web启动器,不需要再添加spring-boot-starter-web 依赖了-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <version>3.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-loadbalancer</artifactId>
            <version>3.1.4</version>
        </dependency>

若父类含有spring-boot-starter-web则引用此依赖以去除web

<!--若父类含有spring-boot-starter-web则引用此依赖以去除web-->
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <scope>test</scope>
        </dependency>

消除缓存警告依赖

		<dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
            <version>2.9.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>5.3.12</version>
        </dependency>

yml配置文件

spring:
	cloud:
		gateway:
		discovery:
        	locator:
				enabled: true #开启从注册中心动态创建路由功能,利用微服务名路由
			routes:
				- id: QIESIYV-ZHUTI-XIAOFEI #路由id 可配置多个不同id
				uri: lb://QIESIYV-ZHUTI-XIAOFEI #若匹配则转发的路由地址,lb是轮询访问服务名,也可以直接uri: http:xxx
				predicates: #断言,所匹配的url规则
					- Path=/ceshi/**
					- Header=token,.* #需要token
				filters: 
					- RewritePath=/ceshi/(?<segment>.*), /aaa/$\{segment} #/ceshi/是被替换/aaa/是替换后
					

意思就是通过此网关访问ceshi/下的任意方法时,会将url前面的域名或者ip端口啥的替换成uri指向的服务

常用断言整理(规定访问转发条件)
常用断言
常用配置断言

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翎墨袅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值