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

相关推荐
lwb_011813 小时前
SpringCloud——Gateway新一代网关
spring·spring cloud·gateway
你是人间五月天13 小时前
gateway断言配置详解
gateway
weixin_3875456414 小时前
深入解析 AI Gateway:新一代智能流量控制中枢
人工智能·gateway
yuluo_YX15 天前
AI Gateway 介绍
人工智能·gateway
网硕互联的小客服17 天前
502 Bad Gateway:服务器作为网关或代理时收到无效响应处理方式
运维·服务器·gateway
sevevty-seven18 天前
什么是Gateway
gateway
秋の花18 天前
【GateWay】和权限验证
java·gateway
欧先生^_^19 天前
org.springframework.cloud.gateway 组件解释
gateway
jarenyVO21 天前
Spring Cloud Gateway 全面学习指南
java·gateway
保持学习ing23 天前
微服务--Gateway网关
java·网关·微服务·gateway