生命不等于是呼吸,生命是活动。——卢梭

GAV

1
2
3
4
5
6
<!--    gateway 网关    -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>

记得要注释掉我们之前引入的web

1
2
3
4
<!--        <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->

配置断言

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
spring:
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
namespace: ruben-dev
file-extension: yml
gateway:
routes:
- id: query_route
uri: https://www.baidu.com
predicates:
- Query=url,baidu
- id: qq_route
uri: https://www.qq.com
predicates:
- Query=url,qq
application:
name: ruben-gateway
server:
port: 8083

然后访问http://localhost:8083/?url=qq就会跳转到https://www.qq.com

访问http://localhost:8083/?url=baidu就会跳转到https://www.baidu.com