Adrian Elder
Adrian Elder

Reputation: 2071

Unable to connect to spring cloud consul (can't set host/port)

I am trying to connect to a consul server from a Spring boot application, which fails because spring cloud consul doesn't seem to read my host configuration.

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8500 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

The documentation says that we need to set the consul host from the bootstrap.properties/yml file. I have tried setting spring.cloud.consul.host in using by yml and properties format:

spring.cloud.consul.host=myhost (with the appropriate format for .properties vs. .yml)

or

spring.cloud.consul.host=myhost - fun fact, this works correctly when passing in as a program argument.

Dependencies:

Upvotes: 2

Views: 3071

Answers (2)

Alan Brown
Alan Brown

Reputation: 21

It sounds like your bootstrap.yml file is not getting loaded. Do you have the spring-cloud starter as a dependency (pom.xml if using Maven to build)? If it's included then the issue is probably to do with how you are starting the app. Are you running from the command line, or using Intellij/Eclipe to run it? There is probably something about the runtime environment that is causing the bootstrap.yml to not get loaded.

Please provide more details around how you are starting this app if you are still having issues with this.

Upvotes: 0

s7vr
s7vr

Reputation: 76004

Cloud consul starter 1.3.x is not compatible with spring boot 2.x so it may be issue. Try with spring boot 1.5.x version instead.

Works for me with both Finchley (2.0.x) and Greenwich cloud version (2.1.x) and spring boot 2.0.x. More here. Compatibility matrix can be found at the bottom of page.

Upvotes: 1

Related Questions