I/O error on GET request for "http://user-service/hi": user-service; nested exception is java.net.Un

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36090463/article/details/82148906

一.场景重现

最近闲暇时间打算系统学习下SpringCloud系统教程,毕竟最近微服务也挺火的,于是网上找了一个大牛的博客跟着一起学习.(史上最简单的SpringCloud教程 ) 一直跟着模仿构建SpringCloud一直也没出什么问题,直到在构建rest+ribbon时,出现了 I/O error on GET request for "http://user-service/hi": user-service; nested exception is java.net.UnknownHostException: user-service 的错误,这个问题直接百度似乎得不出答案来,由于我对SpringCloud的不了解,导致我看了许多博客与实践后,才找到解决方法.

二.我报错之前的配置(关键配置)

 application.yml

spring:
  application:
    name: user-service
server:
  port: 8764
eureka:
  instance:
    hostname: user-service
  client:
    serviceURL:
      defaultZone: http://localhost:8761/eureka/

user.pom

	<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		</dependency>

三.解决后的正常配置(关键配置)

 application.yml

spring:
  application:
    name: user-service
server:
  port: 8764
eureka:
  client:
    serviceURL:
      defaultZone: http://localhost:8761/eureka/

这里主要是去掉了eureka:
                                 instance:
                                     hostname: user-service 

user.pom

	<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

这里主要是将spring-cloud-starter-netflix-eureka-server 修改至spring-cloud-starter-netflix-eureka-client

四.结果展示

 

猜你喜欢

转载自blog.csdn.net/qq_36090463/article/details/82148906