栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

记一次Spring Cloud Gateway网关返回空的{}问题解决

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

记一次Spring Cloud Gateway网关返回空的{}问题解决

问题截图如下:

spring cloud gateway application.yml配置(备注:使用bootstrap.yml会导致gateway服务无法正确注册到nacos,报服务名称找不到)

spring:
  application:
    name: gateway
  cloud:
    nacos:
      username: nacos
      password: nacos
      server-addr: 127.0.0.1:8848
    gateway:
      discovery:
        locator:
          enabled: true # gateway可以通过开启以下配置来打开根据服务的serviceId来匹配路由,默认是大写
      routes:
        - id: muRoute
          uri: lb://customer
          #uri: http://localhost:18085
          predicates:
             - Path=/api/** #这是错误写法,会导致gateway配置不到路径,从而返回{},正确如下
          - Path=/api/**
    sentinel:
      transport:
        clientIp: 10.6.20.114
        port: 8888 #跟控制台通讯的端口
        dashboard: localhost:9090 # 指定控制台服务的地址
server:
  port: 18088

这个问题花了我很久的时间,一直找不到问题的原因,看到官网文档才恍然大悟,难受的一批

lb://customer:代表的意思是使用负载均衡的方式路由服务,所以需要在项目导入如下依赖

    
    
      org.springframework.cloud
      spring-cloud-starter-loadbalancer
    

    
      com.alibaba.cloud
      spring-cloud-alibaba-sentinel-gateway
    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1007200.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号