title: Not able to read configuration from Consul in spring-boot application
body: <p>I am creating a <code>Spring Boot</code> application, which will read configuration like DB properties from <code>Consul</code>. But I am not able to read the key value from Consul using my application. Following is, what I am trying to do.</p>
  
  <pre><code>**pom.xml**
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.tuturself&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-consul&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.4.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;spring.retry.version&gt;1.2.1.RELEASE&lt;/spring.retry.version&gt;
          &lt;consul.version&gt;1.1.2.RELEASE&lt;/consul.version&gt;
          &lt;consul.discovery.version&gt;1.1.2.RELEASE&lt;/consul.discovery.version&gt;
          &lt;jackson.version&gt;2.8.1&lt;/jackson.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&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-consul-discovery&lt;/artifactId&gt;
              &lt;version&gt;${consul.discovery.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;
          &lt;/dependency&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;version&gt;${spring.retry.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.5.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;repackage&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-consul-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;1.2.1.RELEASE&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>And Following is my Main class:</strong></p>
  
  <pre><code>@EnableRetry
  @RefreshScope
  @EnableDiscoveryClient
  @SpringBootApplication
  @ComponentScan("com.test.*")
  public class SpringBootConsulApplication {
  
      private static ConsulConfiguration consulConfiguration;
  
      public static void main(String[] args) {
          try {
              String consulHost = System.getProperty("spring.cloud.consul.host");
              System.out.println("consulHost ::" + consulHost);
              String consulPort = System.getProperty("spring.cloud.consul.port");
              System.out.println("consulPort ::" + consulPort);
              String consulPrefix = System.getProperty("spring.cloud.consul.config.prefix");
              System.out.println("consulPrefix ::" + consulPrefix);
              new SpringApplicationBuilder(SpringBootConsulApplication.class).web(true).run(args);
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>And I am reading the consul properties using the <code>@Value</code> annotation:</p>
  
  <pre><code>@Configuration
  @EnableConfigurationProperties(PropertySourceBootstrapProperties.class)
  public class ConsulConfiguration {
  
      @Value("${cassandra.host}")
      private String cassandraHost;
  
      @Value("${cassandra.user}")
      private String userName;
  
      @Value("${cassandra.password}")
      private String password;
  }
  </code></pre>
  
  <p>I have my <code>bootstrap.yml</code> in resources folder:</p>
  
  <pre><code>spring:
    cloud:
      consul:
        host: localhost
        port: 8500
        enabled: true
        config:
          enabled: true
          prefix: config/application
          defaultContext: apps
          profileSeparator: '::'
    application:
      name: spring-boot-consul
  </code></pre>
  
  <p>Consul is up and running in my local system on <code>localhost:8500</code> where I have the file <code>config/application/spring-boot-consul.yml</code> file;</p>
  
  <pre><code>spring:
    application:
      name: spring-boot-consul
  cassandra:
    host: 127.0.0.1:9042,127.0.0.2:9042
    user: my_user
    password: my_pass
    pooling:
      maxThread: 10
      timeout: 50
    keyspace:
      name: test_keyspace
      readConsistency: ONE
      writeConsistency: ONE
  </code></pre>
  
  <p>When I am strating the application, it is showing not able to bind <code>cassandra.host</code> in my <code>ConsulConfiguration</code>  class. Thus stopping the application. Any hints , What I am doing wrong here?</p>