【发布时间】:2020-04-01 10:56:28
【问题描述】:
我配置了一个 eureka 服务器,并且在该 eureka 服务器内我编写了一个 rest api。现在我有一个 eureka 客户端服务,我正在尝试使用客户端服务中的 feign 调用 eureka 服务的方法之一。但我收到错误消息“负载均衡器没有可用于客户端的服务器:eureka-service”。
但是,如果我使用 feign 从客户端服务调用 api 到另一个客户端服务,那么它会给出成功的结果。只是无法从 eureka 服务调用 API。
eureka-service 是我的 eureka 服务器的应用程序名称。
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
@RestController
@RequestMapping("test")
public class TestController {
@GetMapping
public String test(){
return "test success";
}
}
eureka服务的bootstrap.yml
eureka:
client:
registerWithEureka: false
fetchRegistry: false
eureka-server-read-timeout-seconds: 60
eureka-server-connect-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8763/eureka/
dashboard:
enabled: true
spring:
application:
name: eureka-service
而客户服务是:
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
@FeignClient("eureka-service")
public interface TestFeign {
@GetMapping("test")
String test();
}
客户端服务的bootstrap.yml
eureka:
client:
registerWithEureka: true
fetchRegistry: true
eureka-server-read-timeout-seconds: 60
eureka-server-connect-timeout-seconds: 60
serviceUrl:
defaultZone: http://localhost:8763/eureka/
spring:
application:
name: client-service
feign:
hystrix:
enabled: true
错误日志:servlet [dispatcherServlet] 的 Servlet.service() 在路径 [] 的上下文中抛出异常 [请求处理失败;嵌套异常是 com.netflix.hystrix.exception.HystrixRuntimeException: TestFeign#test() failed and no fallback available.] 根本原因 com.netflix.client.ClientException:负载均衡器没有可用于客户端的服务器:eureka-service。
我们如何解决这个问题。提前感谢您的帮助。
【问题讨论】:
标签: spring-boot microservices netflix-eureka spring-cloud-feign