【发布时间】:2021-02-26 09:50:11
【问题描述】:
我正在尝试创建一个简单的 Spring Cloud Config 服务器/客户端设置,并且大致遵循文档:
https://cloud.spring.io/spring-cloud-config/reference/html/
到目前为止,我已经实现了一个似乎可以正常工作的服务器,即当我调用相应的端点时返回正确的属性值:
GET http://localhost:8888/config-client/development
{
"name": "config-client",
"profiles": [
"development"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/config/config-client-development.properties",
"source": {
"user.role": "Developer"
}
}
]
}
但是,我无法让客户端连接到服务器。我做了以下事情:
- 添加了
spring-cloud-starter-config依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
- 添加了
bootstrap.properties文件:
spring.application.name=config-client
spring.profiles.active=development
spring.cloud.config.uri=http://localhost:8888
但我仍然得到一个
java.lang.IllegalArgumentException: Could not resolve placeholder 'user.role' in value "${user.role}"
尝试运行客户端应用程序时。
应用程序日志中没有任何内容显示客户端正在尝试与配置服务器进行通信。
链接到重现问题的 minimal GitHub 存储库: https://github.com/Bragolgirith/spring-cloud-minimal
重现步骤:
- 构建并运行
config-service应用程序 - 构建并运行
config-client应用程序
知道我做错了什么吗?
【问题讨论】:
-
我会检查的
标签: spring-boot spring-cloud spring-cloud-config