Feign Client无法与eureka服务器内部的方法通信

问题描述 投票:0回答:1

我已配置了一个eureka服务器,并且在该eureka服务器中编写了一个REST API。现在,我有一个eureka客户服务,我试图使用来自客户服务的伪装来调用eureka服务的一种方法。但是我收到一个错误“负载均衡器没有适用于客户端的服务器:eureka服务”。

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:
 client:
  registerWithEureka: false # This tells this service to register with eureka.
  fetchRegistry: false # since its not eureka, we make its local copy true
  eureka-server-read-timeout-seconds: 60
  eureka-server-connect-timeout-seconds: 60
  serviceUrl:
   defaultZone: http://localhost:8763/eureka/ 
 dashboard:
  enabled: true

并且客户服务是:

@FeignClient("eureka-service")
public interface TestFeign {
  @GetMapping("test")
  String test();
}

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

错误日志:路径为[]的Servlet [dispatcherServlet]的Servlet.service()引发异常[请求处理失败;嵌套的异常是com.netflix.hystrix.exception.HystrixRuntimeException:TestFeign#test()失败并且没有可用的后备。]根本原因com.netflix.client.ClientException:负载均衡器没有适用于客户端的服务器:eureka-service。

我们如何解决这个问题。预先感谢您的帮助。

spring-boot microservices netflix-eureka spring-cloud-feign
1个回答
0
投票

您需要扫描在主类中带有FeignClients注释的接口,声明它们为@EnableFeignClients

© www.soinside.com 2019 - 2024. All rights reserved.