当前位置: 首页 > news >正文

Gateway结合nacos(lb://xxx)无效问题

Gateway结合nacos无效

版本如下:
com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2021.0.1.0
org.springframework.cloud:spring-cloud-starter-gateway:3.1.1
配置如下:

server:port: 7000
spring:application:name: springCloudGatewaycloud:nacos:discovery:server-addr: xxx.xxx.xxx.xx:8848username: xxxpassword: xxxgateway:routes:- id: product_routeuri: lb://nacos-consumerpredicates:- Path=/consumer/**filters:- StripPrefix=1

我测试过了,使用http://localhost:xxx的方式就可以访问
lb:和http:的区别就在于,一个是固定的访问地址,一个是使用负载均衡去访问,所以问题出来负载均衡这里
在网上找到解决方案说是添加一个loadBalancer依赖就好了

		<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId><version>3.1.1</version></dependency>

问题解决!但为什么我添加一个负载均衡依赖就好了?
我科学上网了一下找到了这个为什么会这样,如下:
在Spring Cloud Gateway 2.x及以上版本中,官方文档已经明确表示不再支持Ribbon作为默认的负载均衡器实现。因此,从这个版本开始,Spring Cloud Gateway不再提供自带的负载均衡器组件。
不过,Spring Cloud Gateway可以与Spring Cloud LoadBalancer集成来实现负载均衡的功能。Spring Cloud LoadBalancer是一个独立的模块,它提供了一个基于服务实例列表的负载均衡器实现,可以与Spring Cloud Gateway和其他Spring Cloud组件一起使用。

也就是说如果你想要在Spring Cloud Gateway中使用lb://service-name这种形式的URI来访问Nacos注册中心的服务,那么需要在依赖中引入Spring Cloud LoadBalancer的相关依赖。

http://www.lryc.cn/news/101715.html

相关文章:

  • NODEJS笔记
  • 无涯教程-jQuery - html( )方法函数
  • Linux vsftp三种模式的简单配置部署
  • 6.1.tensorRT高级(1)-概述
  • 【Python】将M4A\AAC录音文件转换为MP3文件
  • 个性新颖纯css手风琴效果选项卡
  • js的sendBeacon方法介绍
  • 【Tomcat---1】IDEA控制台tomcat日志输出乱码解决
  • Redis学习路线(2)—— Redis的数据结构
  • 【Redis深度专题】「核心技术提升」探究Redis服务启动的过程机制的技术原理和流程分析的指南(持久化功能分析)
  • IT管理者年过50后何去何从
  • C++字符串题基础(进阶请看下一个文章)
  • webpack如何实现热更新?
  • REST API的基础:HTTP
  • 基于Docker-compose创建LNMP环境并运行Wordpress网站平台
  • 【雕爷学编程】MicroPython动手做(02)——尝试搭建K210开发板的IDE环境3
  • Java语言跨平台执行的核心JVM
  • 家政服务小程序制作攻略揭秘
  • 2023-07-29力扣每日一题
  • Dual pyramid GAN for semantic image synthesis
  • 【Linux】更换jdk版本
  • web-暴力破解密码
  • 基础实验篇 | CopterSim中回传提示消息实验
  • vue基础-动态style
  • vue3使用响应式数据 + v-model导致响应式失效el-form表单无法输入的问题
  • 线段树详解 原理解释 + 构建步骤 + 代码(带模板)
  • Java中Timer的使用
  • 关于EJB,这两文把热闹和门道都说清楚了
  • MixFormerV2: Efficient Fully Transformer Tracking
  • K8S中网络如何通信