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

相关推荐
三口吃掉你3 天前
微服务之网关(Spring Cloud Gateway)
java·网关·微服务·gateway
余衫马3 天前
微服务SpringCloud报错合集
spring boot·gateway
Zz_waiting.3 天前
统一服务入口-Gateway
java·开发语言·gateway
菲兹园长5 天前
微服务组件(E、L、N、O、G)
linux·服务器·gateway
tuokuac7 天前
依赖spring-cloud-starter-gateway与spring-cloud-gateway-dependencies的区别
java·gateway
洛克大航海9 天前
9-SpringCloud-服务网关 Gateway-高级特性之 Filter-2
java·spring cloud·gateway·filter
洛克大航海10 天前
9-SpringCloud-服务网关 Gateway-高级特性之 Filter-1
spring·spring cloud·gateway·filter
yangmf204010 天前
如何使用 INFINI Gateway 增量迁移 ES 数据
大数据·数据库·elasticsearch·搜索引擎·gateway
非凡的世界11 天前
ThinkPHP6 集成TCP长连接 GatewayWorker
网络·网络协议·tcp/ip·gateway·thinkphp·worker·workman
戮戮11 天前
一次深入排查:Spring Cloud Gateway TCP 连接复用导致 K8s 负载均衡失效
tcp/ip·spring cloud·kubernetes·gateway·负载均衡·netty