我可以在Spring Cloud Config Server中托管JSON文件吗? [英] Can I host JSON file in Spring Cloud Config Server?
问题描述
我们正在使用Spring Cloud Config Server托管Spring Boot应用程序的所有配置。我们希望从Config Server中检索大量的JSON文本。
我们当前的方法是将json文本定义为属性值
myproperty.jsontext = {'name':'value'}
除了将JSON文本定义为属性值之外,还可以通过任何方式托管&从配置服务器获取它?
Spring Cloud Config Server是否支持.json文件?
更新(其他问题):
我可以按以下方式访问searchLocations属性吗?
@Value( $ {spring.cloud.config.server.native.searchLocations}
在进出时,我们不断遇到以下错误
作者:java.lang.IllegalArgumentException:无法解析字符串值 $ {spring.cloud.config.server.native.searchLocations}
的占位符'spring.cloud.config.server.native.searchLocations'
解决方法
yaml
是 Json
的子集,您可以存储 Json
包含在 Yaml
文件中的内容。
- 创建q文件config.yaml
- 在其中添加Json内容
- 在
yaml
,<$ c $中请求文件c> json 和properties
一切正常!
< >在将现有Node.js应用程序集成到Config Service(其中所有配置都在
.json
文件中)时,测试了这种方法。因此,我只是将所有这些都重命名并添加到Config Repo中。 We are using Spring Cloud Config Server to host all configurations for our Spring Boot applications. We want a huge JSON text to be retrieved from the Config Server.
Our current approach is to define the json text as a property value
myproperty.jsontext="{'name':'value'}"
Apart from defining the JSON text as a property value, is there any way to host & fetch it from the config server ?
Does Spring Cloud Config Server support a .json file ?
Update (additional Question):
Can i access the searchLocations property as follows ?
@Value("${spring.cloud.config.server.native.searchLocations}
while acessing, we keep getting the following error
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.cloud.config.server.native.searchLocations' in string value "${spring.cloud.config.server.native.searchLocations}"
Workaround
Since yaml
is a subset of Json
, you can store a Json
content inside of a Yaml
file.
- Create q file config.yaml
- Add the Json content in it
- Request the file in
yaml
,json
andproperties
and everything works!
I have tested this approach when integrating an existing Node.js app to Config Service where all the configs were in .json
file. So, I just renamed all of them and added to a Config Repo.
这篇关于我可以在Spring Cloud Config Server中托管JSON文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!