【问题标题】:Unable to connect to spring cloud consul (can't set host/port)无法连接spring cloud consul(无法设置主机/端口)
【发布时间】:2019-06-12 19:45:53
【问题描述】:

我正在尝试从 Spring boot 应用程序连接到 consul 服务器,但由于 spring cloud consul 似乎没有读取我的主机配置而失败。

引起:org.apache.http.conn.HttpHostConnectException:连接到 localhost:8500 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] 失败:连接被拒绝:连接

文档说我们需要从bootstrap.properties/yml 文件中设置领事主机。我尝试将spring.cloud.consul.host 设置为ymlproperties 格式使用:

spring.cloud.consul.host=myhost.properties.yml 的格式适当)

spring.cloud.consul.host=myhost - 有趣的是,当作为程序参数传入时,它可以正常工作。

依赖关系

  • spring-boot-starter-parent - 2.0.4.RELEASE
  • spring-cloud-starter-consul-all - 1.3.2.RELEASE

【问题讨论】:

  • 您是否检查过 consul 端口是否可以使用 telnet localhost 8500 之类的东西进行 ping 操作?
  • 你确定你设置的属性文件真的被读取了吗?

标签: java spring-boot properties-file spring-cloud-consul


【解决方案1】:

Cloud consul starter 1.3.x 与 spring boot 2.x 不兼容,因此可能存在问题。尝试使用 spring boot 1.5.x 版本。

适用于 Finchley (2.0.x) 和 Greenwich 云版本 (2.1.x) 以及 spring boot 2.0.x。更多here。兼容性矩阵可以在页面底部找到。

【讨论】:

    【解决方案2】:

    听起来你的 bootstrap.yml 文件没有被加载。您是否将 spring-cloud 启动器作为依赖项(如果使用 Maven 构建,则为 pom.xml)?如果包括在内,则问题可能与您启动应用程序的方式有关。您是从命令行运行,还是使用 Intellij/Ecipe 运行它?运行时环境可能有一些原因导致 bootstrap.yml 无法加载。

    如果您对此仍有疑问,请提供有关如何启动此应用的更多详细信息。

    【讨论】:

      猜你喜欢
      • 2016-07-05
      • 2018-07-06
      • 1970-01-01
      • 2016-12-13
      • 2012-12-21
      • 1970-01-01
      • 2015-05-22
      • 2016-12-01
      • 2015-03-19
      相关资源
      最近更新 更多