27.使用GateWay


想要使用GateWay

1.开启服务注册发现(配置nacos的注册中心地址)

加上@EnableDiscoveryClient

代码如下(示例):
application.properties(配置注册中心)

spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.application.name=gulimall-gateway
server.port=88

bootstrap.properties(配置配置中心)

spring.application.name=gulimall-coupon
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.namespace=738d1275-36f1-4830-926a-7d152f92052f

2.在Nacos中注册

1.创建gateway这个命名空间
2.➕gulimall-gateway.yml这个Data Id
3.发布

sping:
   application:
      name: gulimall-gateway

关于gulimall-gataway启动
在application.yml文件配置路由

spring:
  cloud:
    gateway:
      routes:
        - id: test_route
          uri: https://www.baidu.com
          predicates:
            - Query=url,baidu

        - id: qq_route
          uri: https://www.qq.com
          predicates:
            - Query=url,qq

        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}
#前端项目,/api

访问 http://localhost:88/?url=qq 即路由到www.qq.com

  • Query=url,baidu这个意思就是 只要url里面含有baidu他就自动跳转www.baidu.co
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值