title: Trying to get Spring/Consul/Vault to work together
body: <p>I'm trying to do something I think is simple. I want to use <a href="https://www.consul.io" rel="nofollow noreferrer">Consul</a> for configuration, and <a href="https://www.vaultproject.io" rel="nofollow noreferrer">Vault</a> for secrets.</p>
  
  <p><strong>What I'm looking for is a simple app like this that allows me to get config and services from Consul, and secrets from Vault.</strong> </p>
  
  <p>In my example, Consul and Vault are connected, and I can see Vault in the Consul services and key-value store.</p>
  
  <p>In Postman, I can query Vault directly and see my data at {{vault_url}}/v1/secret/interservice-bus/data-categorizer</p>
  
  <p>Right now I cannot see Consul or Vault values in the test app.</p>
  
  <p>My application.yml is simple</p>
  
  <pre><code>spring:
    profiles:
      active: dev
    main:
      banner-mode: "CONSOLE"
    application:
      name: test-consul
  
  logging:
    level:
      org: INFO
  </code></pre>
  
  <p>The bootstrap.yml is where I'm doing most of my configuration. Some of it is repeated, because Spring complains if different parts are missing. I'm not sure why.</p>
  
  <pre><code>spring:
      profiles: 
          active: vault, dev
      cloud:
          consul:
              host: 127.0.0.1
              port: 8500
              config:
                  enabled: true  
              discovery:
                  prefer-ip-address: true
          config:
              discovery:
                  enabled: true
                  service-id: vault 
              server:
                  vault:
                      host: localhost
                      port: 8200
                      scheme: http
                      authentication: TOKEN
                      token: 00000000-0000-0000-0000-000000000000
          vault:            
              host: localhost
              port: 8200
              scheme: http
              connection-timeout: 5000
              read-timeout: 15000
              authentication: TOKEN
              config:
                  order: -10
              token: 00000000-0000-0000-0000-000000000000
              discovery:
                  enabled: true
                  service-id: vault
  </code></pre>
  
  <p>The token is obscured above, but does match the root token for the vault.</p>
  
  <p>Here's my POM</p>
  
  <pre><code>&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;edu.dkist&lt;/groupId&gt;
      &lt;artifactId&gt;test-consul&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;test-consul&lt;/name&gt;
      &lt;description&gt;Small test to see if consul can work with vault&lt;/description&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.8.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;spring-cloud.version&gt;Dalston.SR4&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-consul-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-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-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&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;/dependencies&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&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;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>And here's the simple app I'm trying to run</p>
  
  <pre><code>package com.example.demo;
  
  import javax.annotation.PostConstruct;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  import org.springframework.cloud.context.config.annotation.RefreshScope;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  @EnableAutoConfiguration
  @RefreshScope
  @SpringBootApplication
  @EnableDiscoveryClient
  public class DemoApplication {
      @Autowired
      org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient;
  
      @Value("${test}")
      private String testString;
  
  
      @Value("${interservice-bus.data-categorizer.username}") 
      private String user;
  
      @Value("${interservice-bus.data-categorizer.password}")
      private String password;
  
  
      @PostConstruct
      public void setRabbitMQLocation() {
              if (discoveryClient == null) {
              System.out.println("******************************ERROR: Discovery Client is null******************************");
              return;
          }
              System.out.println("****************************** Discovery Client is ACTIVE ******************************");
  
          org.springframework.cloud.client.ServiceInstance serviceInstance =
                  discoveryClient.getInstances("interservice-bus")
                          .stream()
                          .findFirst()
                          .orElseThrow(() -&gt; new RuntimeException("ERROR: " + "interservice-bus" + " not found"));
          System.out.println("****************************** ISB is " + serviceInstance.getHost() + ":" + serviceInstance.getPort() + " ******************************");
      }
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  }
  </code></pre>
  
  <p>It's not finding "test". I am trying to pull the username and password from Vault, and test from Consul.</p>
  
  <p>I'm getting </p>
  
  <pre><code>Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  2018-06-20 16:30:33.580 ERROR 92722 --- [           main] o.s.boot.SpringApplication               : Application run failed
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.demoApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'test' in value "${test}"
  </code></pre>
  
  <p><strong>What I'm looking for is a simple app like this that allows me to get config and services from Consul, and secrets from Vault.</strong> </p>
  
  <p>From searching on the net and looking at examples, it's not clear to me if I need to pull in the Vault dependencies as well or if I'm getting everything from Consul (and thus don't need the Vault dependencies).  </p>