【问题标题】:Feign Client cannot communicate with a method inside of eureka serverFeign Client 无法与 eureka 服务器内部的方法通信
【发布时间】: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


    【解决方案1】:

    您需要在主类中使用@EnableFeignClients 注释扫描声明它们为FeignClients 的接口,并添加feign.hystrix.enabled=true 属性。

    【讨论】:

    • 对不起先生。但是我已经在主类中声明了@EnableFeignClients,并且在客户端服务的属性字段中声明了 feign.hystrix.enabled=true。还是不行
    猜你喜欢
    • 2016-08-04
    • 2020-02-22
    • 2014-03-07
    • 2021-09-13
    • 1970-01-01
    • 2020-08-05
    • 2016-05-17
    • 2016-08-13
    • 1970-01-01
    相关资源
    最近更新 更多