我正在尝试使用spring-cloud-consul
从Consul KV商店获取价值密钥存在: 卷曲http://localhost:8500/v1/kv/config/HelloWorldClient/testKey [{" LockIndex":0,"键":"配置/ HelloWorldClient /密押""标志":0,"值":" Y29uc3VsVGVzdEtleQ ==""的CreateIndex":2748497," ModifyIndex":2748497}]
这是我的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
样本控制器:
@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();
}
}
我收到错误:使用名称' consulValuesGetter'创建bean时出错:注册自动连接的依赖项失败;嵌套异常是java.lang.IllegalArgumentException:无法解析占位符' testKey'在价值" $ {testKey}"
我看到这个条目: 位于属性源:CompositePropertySource [name =' consul',propertySources = [ConsulPropertySource [name =' config / HelloWorldClient /'],ConsulPropertySource [name =' config / application / ']]]
Maven有:
<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>
请帮助解决此问题。 谢谢。