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

相关推荐
波波烤鸭1 天前
深入理解 Gateway 网关:原理、源码解析与最佳实践
java·spring·gateway
DO_Community1 天前
DigitalOcean Kubernetes 现已支持 Gateway API 托管服务
容器·kubernetes·gateway
T_Ghost1 天前
SpringCloud微服务网关Gateway
spring cloud·微服务·gateway
Rysxt_3 天前
Spring Boot Gateway 教程:从入门到精通
spring boot·网关·gateway
月夕·花晨3 天前
Gateway -网关
java·服务器·分布式·后端·spring cloud·微服务·gateway
sanggou4 天前
License 集成 Spring Gateway:解决 WebFlux 非阻塞与 Spring MVC Servlet 阻塞兼容问题
spring·gateway·mvc
摘星编程10 天前
Nginx 502 Bad Gateway:从 upstream 日志到 FastCGI 超时复盘
网络·nginx·gateway·php-fpm·fastcgi
网硕互联的小客服10 天前
504 Gateway Timeout:服务器作为网关或代理时未能及时获得响应如何处理?
运维·服务器·gateway
Pierre_10 天前
通过SpringCloud Gateway实现API接口镜像请求(陪跑)网关功能
spring·spring cloud·gateway
kk在加油11 天前
智能门卫:Gateway
gateway