我们用的是Spring Cloud Config 2.1版本,可以使用,我们更新到Spring Cloud Config 2.2,现在不能使用了。https:/github.comspring-cloudspring-cloud-configissues1599。我报这个问题也是为了加快进程,或者说这不是问题。我不知道,所以请大家帮忙。
我们的配置文件。python -service.yml
resources:
- resource1
- resource2
newResources: []
正如我所了解到的,Spring Cloud配置客户端发出请求来获取配置,它通过header
Accept: application/vnd.spring-cloud.config-server.v2+json
.在Spring Cloud config v 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"
}
如果我去掉accept头,会得到(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": ""
变成了一个空的字符串,如果预期是一个空数组--这是另一个问题。
"newResources": ""
变成了一个空字符串,如果我希望是一个空数组的话。目前,我可以从我的配置中删除空数组,但这是非常可怕的,因为我们的配置在许多服务中使用!这破坏了向后的兼容性。这破坏了向后的兼容性。
原来,这是Spring Boot的一个BUG。
https:/github.comspring-cloudspring-cloud-configissues1572#issuecomment-620496235。
https:/github.comspring-projectsspring-bootissues20506。
可能的选择。
1)等到修好了再更新库。
2)我们做了什么。我们用空元素替换了空数组。
newResources:
anotherField: value
或者,使用 null
. 但是,请确保你的代码可以处理它。另外,空数组也可以作为一个 emptyString
. 我在调试器中发现了这个问题。