关于gateway中lb失效

在通过gateway将请求发送到对应的服务模块时,出现了503的报错,也就是gateway时可以正常启动,但是页面上在发送请求获取数据的时候,却不是相应的请求地址。

解决方法:

1.首先你得保证前端项目里面访问网关地址都是正确的。

2.检查一下你的nacos中服务和网关是否在同一个命名空间和分组中。

3.检查一下你的配置有没有写错(漏写了什么标点符号什么的)。

复制代码
spring:
  cloud:
    gateway:
      routes:
        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath= /api/(?<segment>.*),/renren-fast/$\{segment}

4.如果还没有解决问题,在你的pom里面加上:

java 复制代码
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
            <version>3.0.1</version>
        </dependency>

注意是spring-cloud-starter-loadbalancer,不是spring-cloud-loadbalancer!!!!

5.如果又出现了其他的报错,比如我的是报错信息说是:

java 复制代码
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.  Reason: Failed to determine a suitable driver class

解决方法就是在启动类上加上:

java 复制代码
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

6.如果又出现了依赖冲突的报错,可以在你的配置类上,也就是yml上加上:

java 复制代码
spring:
  main:
    allow-circular-references: true

7.如果上面还是没有解决你的问题,你就仔细检查一下你的springboot和springcloud的版本是否对应,当然你已经做到了这一步,大概率说明你的版本是没有什么问题的,但还是要仔细检查一下,你是否有的地方粗心了一些。

8.基本上你的报错信息呈现在控制台之后,你都可以根据报错信息找到问题在哪里,如果自己还是解决不了,那就只能去百度了,如果百度解决不了,最好的方法就是问问你身边的人。

相关推荐
亚林瓜子17 小时前
AWS API Gateway配置日志
云计算·gateway·aws·log·cloudwatch
惊鸿一博1 天前
java_网络服务相关_gateway_nacos_feign区别联系
java·开发语言·gateway
hanniuniu131 天前
网络安全厂商F5推出AI Gateway,化解大模型应用风险
人工智能·web安全·gateway
stormsha2 天前
Proxmox Mail Gateway安装指南:从零开始配置高效邮件过滤系统
服务器·网络·网络安全·gateway
背太阳的牧羊人2 天前
backend 服务尝试连接 qdrant 容器,但失败了,返回 502 Bad Gateway 问题排查
docker·gateway·qdrant
曼彻斯特的海边3 天前
RequestRateLimiterGatewayFilterFactory
spring cloud·gateway·限流
·云扬·3 天前
【PmHub面试篇】Gateway全局过滤器统计接口调用耗时面试要点解析
面试·职场和发展·gateway
devil_mf3 天前
gateway 网关 路由新增 (已亲测)
gateway
wmd131643067123 天前
Gateway 搭建
gateway
KubeSphere 云原生5 天前
云原生周刊:探索 Gateway API v1.3.0
云原生·gateway