java - Ribbon 客户端无法发现在 eureka 中注册的微服务

标签 java spring-boot microservices netflix-eureka netflix-ribbon

您好,我创建了两个微服务 1.spotparkin 和 2.spotparking2,它们已成功注册到 eureka 服务器,然后我创建了功能区客户端并尝试使用应用程序名称 Spotpaking 进行休息调用,这是我在中给出的应用程序名称两个微服务中都有 application.yml 文件,但我收到以下错误:

2016-10-16 13:28:35.177 ERROR 11304 --- [nio-7213-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in c ontext with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GE T request for "http://spotparking/spotparking/pincode": spotparking; nested exception is java.net.UnknownHostException: spotparking] with root cause

java.net.UnknownHostException: spotparking at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_101]

ParkingSpot parkingSpot = restTemplate.exchange("http://spotparking/spotparking/{pincode}",HttpMethod.GET,null,new ParameterizedTypeReference<ParkingSpot>() {}, pincode).getBody();
        return new MessageWrapper<>(parkingSpot, "server called using eureka with rest template");

This is how it is comming up in eureka:  

enter image description here

源代码可在 https://github.com/focode/microservices2/ 上获取

最佳答案

功能区中缺少@LoadBalanced 并且还添加了

client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka/
    lease:
      duration: 5

代码现在可以运行,可以从我的 github 帐户获取

关于java - Ribbon 客户端无法发现在 eureka 中注册的微服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40068318/

相关文章:

java - 在微服务架构中聚合原始数据分析的位置

java - Yajsw Stop INFO Log message while start stop daemon 在linux下

java - Spring - 使用值注释从本地配置文件中读取

java - 从可执行 jar 创建随处安装启动器

java - 在微服务架构中,为什么他们说共享 REST Client 库不好?

java - 微服务与事件溯源 (CQRS) 交互的最佳实践

java - 甲骨文 : select words which start by character or associated special character

java - 无法在 jTextField 中显示数据

java - Selenium webdriver 选择

Spring Boot异常处理最佳实践