我正在尝试创建一个简单的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}"
尝试运行客户端应用程序时。
应用程序日志中没有任何内容,甚至看起来好像客户端正在尝试与配置服务器进行通信。
链接到可重现此问题的最小GitHub存储库:https : //github.com/Bragolgirith/spring-cloud-minimal
重现步骤:
config-service
应用程序config-client
应用程序知道我在做什么错吗?
好,雾气解决了。
似乎在一周前发布了新的Spring Cloud版本(https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available)有一种新的方式来启动引导过程-默认情况下它不会发生,但是需要添加其他依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
尽管此新版本现在是使用Spring Initializr时获得的默认版本,但文档仍未更新以反映更改-在发行说明中仅简要提及了它们。
作为使用新的spring-cloud-starter-bootstrap
依赖项和bootstrap.properties
文件的替代方法,现在似乎还可以实现以下功能:
application.properties
spring.application.name=config-client
spring.profiles.active=development
spring.config.import=configserver:http://localhost:8888
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句