I am trying to get a value from Consul KV store using spring-cloud-consul
Key exist: curl http://localhost:8500/v1/kv/config/HelloWorldClient/testKey [{"LockIndex":0,"Key":"config/HelloWorldClient/testKey","Flags":0,"Value":"Y29uc3VsVGVzdEtleQ==","CreateIndex":2748497,"ModifyIndex":2748497}]
This is my bootstrap.yml
spring:
application:
name: HelloWorldClient
cloud:
consul:
config:
enabled: true
format: YAML
prefix: config
default-context: apps
fail-fast: true
data-key: data
host: localhost
port: 8500
enabled: true
Sample controller:
@EnableDiscoveryClient
@Controller
@EnableConfigurationProperties(PropertySourceBootstrapProperties.class)
public class ConsulValuesGetter {
@Value("${testKey}")
String testKeyValue;
@Autowired
private Environment env;
@GetMapping("/getKey")
public String helloClient() {
System.out.println("Test KEY= " + null + "ENV: " + env.toString());
return env.toString();
}
}
I am getting error: Error creating bean with name 'consulValuesGetter': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'testKey' in value "${testKey}"
I see this entry: Located property source: CompositePropertySource [name='consul', propertySources=[ConsulPropertySource [name='config/HelloWorldClient/'], ConsulPropertySource [name='config/application/']]]
Maven has:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-dependencies</artifactId>
<version>1.2.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Please help to resolve this problem. Thank you.