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

相关推荐
whz-emm1 天前
vLLM加载lora
gateway
青衫客363 天前
Portkey-AI gateway 的一次“假压缩头”翻车的完整排障记:由 httpx 解压异常引发的根因分析
大模型·llm·gateway·httpx
PXM的算法星球7 天前
spring gateway配合nacos实现负载均衡
spring·gateway·负载均衡
1990_super8 天前
使用ceph-deploy安装和配置RADOS Gateway (RGW)并使用S3访问集群
ceph·gateway
北极糊的狐11 天前
接口返回504 Gateway Time-out 错误,这意味着请求在网关或代理服务器等待上游服务器响应时超时。以下是可能的原因和排查建议:
数据库·gateway
sg_knight12 天前
Spring Cloud Gateway全栈实践:动态路由能力与WebFlux深度整合
java·spring boot·网关·spring·spring cloud·微服务·gateway
放纵日放纵14 天前
微服务—Gateway
微服务·架构·gateway
你我约定有三14 天前
分布式微服务--GateWay(1)
java·开发语言·分布式·微服务·架构·gateway
William一直在路上18 天前
KONG API Gateway中的核心概念
网络·gateway·kong