Search code examples
javadocker-composespring-cloudmicroservicesspring-cloud-config

Solve dependencies on docker-compose


I have a Spring boot microservice connecting to a Spring configuration service to get the config, but apparently, the service cannot start after the config server it's completely up and running, otherwise it will never be able to connect again (?)

Here's the error I see in the service's console when I run the docker-compose file:

2016-04-07 14:25:51.305 WARN 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://configserver:8888/myservice/default": Connection refused; nested exception is java.net.ConnectException: Connection refused

Here's my docker-compose file:

discovery:
  image:discovery-service
  ports:
   - "8761:8761"
configserver:
  image:config-service
  ports:
   - "8888:8888"
  links:
   - discovery
myservice:
  image:my-service
  ports:
   - "9006:9006"
  links:
   - discovery
   - configserver

And this is the service bootstrap.yml config:

spring:
  application:
    name: myservice
  cloud:
    enabled: true
    config:
      uri: http://configserver:8888
encrypt:
  failOnError: false

Once both services are running and registered on Eureka (discovery), I try to call /refresh on myservice but it keeps failing and returning the same error.

If I restart the docker instance it connects without issues.

Does that mean I have to keep the config server running continuously to be able to do that?


Solution

  • You need to configure the client app to be more robust if the config server is not ready yet when it starts. there's a section in the user guide. TL;DR include spring-retry and set spring.cloud.config.failFast=true.