今天搭建Spring-Cloud-Eureka-Server 和client的demo,由于之前没有做过相关项目,碰到一个问题时,解决起来浪费了不少时间,问题如下:

client启动时,报了如下错误:

2017-09-18 11:27:32.317  WARN 2712 --- [freshExecutor-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: Connection refused: connect
2017-09-18 11:27:32.318 ERROR 2712 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_TESTCLIENT/DESKTOP-DBS1AMN:testClient:8762 - was unable to refresh its cache! status = Cannot execute request on any known server

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

找了几篇博客,通过不断的对比与测试,发现了问题所在:

在server端的application.yml中配置了登陆Eureka服务端的用户名和密码:

security:
  basic:
    enabled: true
  user:
      name: admin # login username
      password: admin

解决方式:

1、删除用户名和密码配置,重启即可;

2、在客户端的application.yml中,serviceUrl配置时,加入用户名和密码:

serviceUrl:
      defaultZone: http://username:password@localhost:8761/eureka/
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐