1:引入SpringCloud Gateway
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
2:路由方式
2.1:配置方式- applicaiton.yml
spring:
application:
name: cloud-gateway
cloud:
gateway:
routes:
- id: path_route
uri: https://www.comang.top
predicates:
- Path=/auth/*
2.2:JavaConfig方式
2.3:Nacos方式
2.3.2: 删除application.yml和RouteConfig文件
2.3.3:配置bootstrap.yml
server:
port: 8080
spring:
application:
name: evaang-gateway
profiles:
active: dev
cloud:
nacos:
# 在 Nacos Spring Cloud 中,dataId 的完整格式:${prefix}-${spring.profiles.active}.${file-extension},其中:prefix 默认为 spring.application.name
config:
server-addr: http://localhost:8848
# nacos配置内容数据格式
file-extension: yaml
2.3.4:配置nacos共享data id(共享DataID不支持@RefreshScope)-
shared-configs:
# 在Nacos控制台添加 share-dev.yaml配置
- share-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}