新创建一个项目取名springcloud-gateway

yml配置
# Tomcat
server:
port: 8088
# Spring
spring:
application:
# 应用名称
name: springcloud-gateway
main:
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 127.0.0.1:8849
gateway:
discovery:
locator:
lowerCaseServiceId: true
enabled: true #开启从注册中心动态创建路由的功能,利用微服务名继续路由
routes:
- id: nacos-payment-consumer # 路由的id,没有规定规则但要求唯一,建议配合服务名
uri: lb://nacos-payment-consumer #匹配后提供服务的路由地址
predicates:
- Path=/aa/** #断言,路径相匹配的进行路由
routes:
- id: nacos-payment-consumer # 路由的id,没有规定规则但要求唯一,建议配合服务名
uri: lb://nacos-payment-consumer #匹配后提供服务的路由地址
predicates:
- Path=/aa/** #断言,路径相匹配的进行路由
这个就是配置动态路由
之前是http://localhost:8001/aa?a=1 现在可以根据http://localhost:8088/aa?a=1 网关地址访问

博客介绍了创建名为springcloud - gateway的新项目,并提及了yml配置用于动态路由。通过配置,可根据网关地址进行访问,聚焦于Spring Cloud Gateway的项目搭建与路由配置相关信息技术内容。
使用gateway网关&spm=1001.2101.3001.5002&articleId=116143712&d=1&t=3&u=1b417891fce645a9aab3cc2ed1c70c43)
4996

被折叠的 条评论
为什么被折叠?



