cloudAlibaba2021.0.5.0geteway的lb失效以及nacos获取错误配置

文章讨论了在使用SpringCloudGateway时,lb://服务名形式的路由失效问题,分析了可能的原因,如依赖版本、服务注册问题等,并提供了修复方法。还涉及Nacos配置错误,尤其是使用`@ConfigurationProperties`时遇到的问题和解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

gateway的lb路由失效

情况一:http://可以正常路由但是lb://服务名的形式不行
	原因:对比了下没问题的练习项目,低版本的gateway依赖中有ribbon和loadblancer相关依赖。
	可能造成这种情况的其他原因:
		目标服务没有正确的注册到nacos中;
		目标服务注册的namespace或者group不同(这是网上看来的,没试过)。
	解决办法:加一个依赖
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
情况二:一开始503,后来变成了500。
	原因:中途做了一个操作就是去改了被调用服务的服务名,从nacos-service改成了nacos_service。
	解决办法:改回  -  就行了

nacos配置值获取错误

情况:代码是使用阿里镜像生成的springboot项目创建时,选择引入依赖后自带的示例代码。代码中获取远程动态配置的类为User类,属性为name和age。其中age可以正常获取,但是name却总是获取到我操作系统的用户名称(不知道是不是操作系统的用户名,只是相同,不确定来源),获取name用的是user.name,nacos远程配置文件也是如此设置。
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zm.nac
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值