I am following this link:
http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage
I tested this again and again and not seeing Spring cloud client is loading configuration from cloud server, please help to see where is the error:
POM:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Application:
@Configuration
@EnableAutoConfiguration
@RestController
public class ConfigclientApplication {
@Value("${spring.cloud.config.uri}")
String url;
@Value("${production.host}")
String host;
@RequestMapping("/")
public String home() {
return "Host is => " + this.host ;
}
public static void main(String[] args) {
SpringApplication.run(ConfigclientApplication.class, args);
}
}
bootstrap.properties:
spring.cloud.config.uri=http://localhost:8888
- The config server is good:
http://localhost:8888/spirent/default
{
"name": "spirent",
"profiles": [
"default"
],
"label": "master",
"propertySources": [
{
"name": "classpath:/spirent.yml",
"source": {
"production.host": "server1",
"production.port": 9999,
"production.value1": 12345,
"test.host": "server2.com",
"test.port": 4444,
"test.value": "hello123"
}
}
]
}
now http://localhost:8080/ can not be started at all.
Error creating bean with name 'configclientApplication'
It seemed the auto inject of @Value can not find the production.host environment value.
How can I read the configuration in client once loaded from config server?
Thanks for your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…