Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I host JSON file in Spring Cloud Config Server?

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}"
like image 203
yathirigan Avatar asked Jul 29 '15 11:07

yathirigan


People also ask

Can spring be configured with a json file?

Our Spring application will support both JSON as well as XML. It will even support XML request with JSON response and vice versa.

When should I use spring cloud config server?

Spring Cloud Config is Spring's client/server approach for storing and serving distributed configurations across multiple applications and environments. This configuration store is ideally versioned under Git version control and can be modified at application runtime.

Where should I put json in spring boot?

json and place it inside of /src/main/resources/json/.

How do I open a json config file?

In the Project Explorer view, expand the plug-in project node. Expand the plugin folder node. Double-click the config. json file, or right-click the file and select Open with > PDK JSON Editor.


2 Answers

there's the possibility to serve arbitary files. It boils down to using the endpoint /{name}/{profile}/{label}/{path} with {path} being the actual filename... So e.g. /a-bootiful-client/default/master/myjson.json will give you the file contents. However by default the content-type of the response will not be application/json but text/html;charset=UTF-8.

However it will also work with "Accept: application/json":

curl -H "Accept: application/json" http://localhost:8888/a-bootiful-client/default/master/a-bootiful-client.json
{
        "propName":"propValue"
}

See the documentation here: http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.3.RELEASE/single/spring-cloud-config.html#_serving_plain_text

like image 74
Korgen Avatar answered Oct 13 '22 01:10

Korgen


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 and properties 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.

like image 20
Marcello de Sales Avatar answered Oct 13 '22 01:10

Marcello de Sales