官方文档地址:
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.1.3.RELEASE/single/spring-clo
ud-gateway.html
1、开启服务注册发现
@EnableDiscoveryClient
在application.properties (配置nacos的注册中心地址)
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.application.name=test
2、创建网关项目,引入网关
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency>
3、编写网关配置文件
spring: cloud: gateway: routes: - id: baidu_route uri: https://www.baidu.com predicates: - Query=url,baidu - id: qq_route uri: https://www.qq.com predicates: - Query=url,qq