【发布时间】:2020-08-07 19:26:33
【问题描述】:
我们使用了 Spring Cloud Config 2.1 版,它工作正常。 我们更新到 Spring Cloud Config 2.2,现在它不起作用。 更多细节是 https://github.com/spring-cloud/spring-cloud-config/issues/1599 我也报告了这个问题以加快进程,或者这可能不是问题。我不知道,所以我请你帮忙。
我们的配置文件:python-service.yml
resources:
- resource1
- resource2
newResources: []
据我所知,Spring Cloud 配置客户端发出请求以获取配置,并传递标头
Accept: application/vnd.spring-cloud.config-server.v2+json。
在 Spring Cloud 配置 v 2.1 中
注意,Spring Cloud 2.1 版不发送此类标头;相反,它发送Accept: application/json
HTTP http://localhost:8888/python-service/dev
Accept: application/vnd.spring-cloud.config-server.v2+json
返回
{
"name": "python-service",
"profiles": [
"dev"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "file:/configuration/python-service.yml",
"source": {
"resources[0]": "resource1",
"resources[1]": "resource2",
"newResources": []
}
}
]
}
但是,它是 Spring Cloud Config v 2.2,它失败了
{
"timestamp": "2020-04-24T08:38:19.803+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Could not construct context for config=python-service profile=dev label=null includeOrigin=true; nested exception is java.lang.NullPointerException",
"path": "/python-service/dev"
}
好笑的是config-service日志中没有异常日志输出!
如果我删除接受标头,我将得到 (version 2.2)
{
"name": "python-service",
"profiles": [
"dev"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "file:/configuration/python-service.yml",
"source": {
"resources[0]": "resource1",
"resources[1]": "resource2",
"newResources": ""
}
}
]
}
这里,为什么"newResources": "" 变成一个空字符串,如果它应该是一个空数组 - 另一个问题。
总结一下
- 1) Spring Cloud config中如何使用空数组。
- 2) 为什么 Spring config-service 日志中没有关于 NPE 的日志消息。
- 3) 如果没有接受头,为什么
"newResources": ""会变成一个空字符串,如果我期望一个空数组。
目前,我可以从我的配置中删除空数组,但这非常可怕,因为我们的配置用于许多服务!这破坏了向后兼容性。
【问题讨论】:
标签: java spring-boot spring-cloud spring-cloud-config