title: consul first bootstrap with spring cloud config
body: <p>Iam using spring-cloud-config for centralized configuration and consul for service discovery. Like eureka first bootstrap - does spring support consul first bootstrap i.e on booting up a client service - I should look up the config server through consul. The otherway round works perfectly fine i.e - in config client bootstrap.properties - I provide the <code>spring.cloud.config.uri</code>=<a href="http://localhost:8888" rel="nofollow">http://localhost:8888</a> which located the config server and pulls config from it. And in the config repository for my client application - I provide the consul config like : </p>
  
  <pre><code>spring.cloud.consul.host=localhost , 
  spring.cloud.consul.port=8500
  </code></pre>
  
  <p>However, when i try to use consul first bootstrap I am unable to read the properties from config server.</p>
  
  <p>Client Application (for consul first bootstrap):</p>
  
  <pre><code>pom.xml
  &lt;parent&gt;
        &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
        &lt;artifactId&gt;spring-cloud-starter-parent&lt;/artifactId&gt;
        &lt;!-- &lt;version&gt;Brixton.BUILD-SNAPSHOT&lt;/version&gt; --&gt;
        &lt;version&gt;Brixton.M5&lt;/version&gt;
        &lt;relativePath /&gt; 
      &lt;/parent&gt;
  &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-aop&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.retry&lt;/groupId&gt;
              &lt;artifactId&gt;spring-retry&lt;/artifactId&gt;
          &lt;/dependency&gt;
       &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-consul-config&lt;/artifactId&gt;
          &lt;/dependency&gt; 
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-consul-all&lt;/artifactId&gt;
          &lt;/dependency&gt;
  &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-zuul&lt;/artifactId&gt;
          &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>bootstrap.properties:</p>
  
  <pre><code>spring.application.name=demo
  spring.cloud.config.failFast=true
  spring.cloud.config.retry.maxAttempts=20
  spring.cloud.config.retry.initialInterval=3000
  spring.cloud.consul.host=localhost
  spring.cloud.consul.port=8500
  </code></pre>
  
  <p>DemoApplication.java</p>
  
  <pre><code>@EnableDiscoveryClient
  @EnableZuulProxy
  @SpringBootApplication
  public class DemoSleuthApplication {
      public static void main(String[] args) {
          SpringApplication.run(DemoSleuthApplication.class, args);
      }
  }
  @RefreshScope
  @RestController
  class RestAPIController 
  {
      @Value(value = "${server.port}")
      String port;
  
      @Value(value = "${message}")
      String message;
  
  @RequestMapping("/message")
        public String welcome(){
            String s = this.restTemplate.getForObject("http://localhost:"+this.port+"/message", String.class);
            return this.message + s;
        }
  }
  </code></pre>
  
  <p>In the consul K/V store
  folder structure config/demo
  Key/Value : <code>spring.cloud.config.uri=http://localhost:8888</code></p>
  
  <p>Config server git repo: not adding the config server code for brevity
  demo.properties</p>
  
  <pre><code>server.port=9080
  message=test
  </code></pre>
  
  <p>Ideally when I implement the concept of consul first bootstrap - I am thinking consul should be started and the client should identify itself using the <code>@EnableDiscoveryClien</code>t annotation and in the consul properties - find config server url , and fetch the config properties from the server configurations. But in my case, service is being discovered and registered in consul but i am not able to read properties from config server git repo.</p>