【解决】使用SpringCloud遭遇Load balancer does not have available server for client

时间:2025-03-23 18:37:51
: 
: 
Load balancer does not have available server for client: answer

场景:我将Eureka服务放于服务器上,两个客户端使用本机启动,一顿瞎操作后,使用 Feign 调用 answer 服务上接口,报以上错误

当时配置如下

=8022
=
=answer
##这两个 true 确实不可缺失
-with-eureka=true
-registry=true
=https://${}/eureka/eureka
=test

解决方式就是将hostname改为当前ip

=localhost

排除1:首先本地是已经启动了 answer 这个服务的,同时在 eureka 页面列表上可以查看到,说明服务代码没问题

排除2:将 maven 中 springboot 依赖全部替换一遍,报错依旧,说明与依赖版本无关

猜测1:是否 Feign 代码问题,例如启动类未加注解等

import ;
import ;
import ;
import ;
import ;
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
@EnableDiscoveryClient
public class AnswerApplication {

    public static void main(String[] args) {
        (, args);
    }

}

对应处理接口的请求使用浏览器主动调用,畅通。

猜测2:调用 answer 服务的接口有问题

import ;
import ;
import ;

@FeignClient(value = "answer")
public interface AnswerFeign {
	
	@RequestMapping(value = "/answerSayHello",method=)
	public String answerFeignTest();
}

与以前的代码比较,没有差异

猜测3: 中配置问题

网上有说加两个配置就解决的,使用后还是无效,但是未删除

-with-eureka=true
-registry=true

瞥一眼 hostname ,猜测 hostname 未必一定用于 defaultzone ,将 hostname 改为本实例IP即可

所以猜测 之前的报错是因为 调用接口方式为::8022/feignTest

这样当然是没有的,正确的应该是 http://localhost:8022/feignTest