Spring Cloud Config:客户端不会尝试连接到配置服务器 [英] Spring Cloud Config: client doesn't attempt to connect to the config server
问题描述
我正在尝试创建一个简单的 Spring Cloud Config 服务器/客户端设置,并且大致遵循文档:
I'm trying to create a simple Spring Cloud Config server/client setup and am loosely following the documentation:
https://cloud.spring.io/spring-cloud-配置/参考/html/
到目前为止,我已经实现了一个似乎可以正常工作的服务器,即当我调用相应的端点时返回正确的属性值:
I've so far implemented a server that seems to work correctly, i.e. return the correct property values when I call the corresponding endpoint:
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"
}
}
]
}
但是,我在让客户端连接到服务器方面没有任何运气.我做了以下事情:
I'm, however, not having any luck with getting the client to connect to the server. I have done the following:
- 添加了
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}"
尝试运行客户端应用程序时.
when trying to run the client application.
应用程序日志中没有任何内容看起来像是客户端正在尝试与配置服务器进行通信.
There is nothing in the application log that even looks like the client is attempting to communicate with the configuration server.
链接到重现问题的最小 GitHub 存储库:https://github.com/Bragogirith/spring-cloud-minimal
Link to a minimal GitHub repository that reproduces the issue: https://github.com/Bragolgirith/spring-cloud-minimal
重现步骤:
- 构建并运行
config-service
应用程序 - 构建并运行
config-client
应用程序
- Build and run the
config-service
application - Build and run the
config-client
application
知道我做错了什么吗?
推荐答案
好的,谜团解决了.
似乎一周前发布了新的 Spring Cloud 版本(https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available) 有一种新的方法来激活引导程序 - 现在默认情况下不会发生,但需要添加额外的依赖项:
It seems a new Spring Cloud version was released a week ago (https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available) that has a new way to activate the bootstrap process - now it doesn't happen by default, but requires adding an additional dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
虽然这个新版本现在是您使用Spring Initializr,文档仍未更新以反映更改 - 它们仅在发行说明中简要提及.
Although this new version is now the default you get when using the Spring Initializr, the documentation is still not updated to reflect the changes - they are only briefly mentioned in the release notes.
作为使用上述 spring-cloud-starter-bootstrap
依赖项和 bootstrap.properties
文件的替代方案,现在似乎以下也是可能的(甚至首选):
As an alternative to using the abovementioned spring-cloud-starter-bootstrap
dependency and a bootstrap.properties
file, it seems the following is now also possible (and even preferred):
application.properties
application.properties
spring.application.name=config-client
spring.profiles.active=development
spring.config.import=configserver:http://localhost:8888
这篇关于Spring Cloud Config:客户端不会尝试连接到配置服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!