Spring Cloud Config serving plain text does not work - spring

I'm trying to fetch configuration as a plain text as explained here:
https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_serving_plain_text
But I can fetch only for .properties, .yml, .json. For other formats like .config, .text, .xml I'm getting 404.
How to resolve it?

I guess you should modify with a few things on the your config server's properties/yaml.
logging.config=${spring.cloud.config.uri}/*/default/master/logback.xml.
etc. Also please share your config server yml with us. This information is not enough.
For More information
can spring cloud config manage xml file
https://cloud.spring.io/spring-cloud-config/multi/multi__serving_plain_text.html

Related

Spring Cloud Config, how to fetch binary files from git repository

Spring cloud-config-server has a built in mechanism to communicate with git repository and read files which are stored there. Then cloud-config-server also has built in mechanism to expose endpoints to clients (normally spring boot apps) which can read those files and use them as configurations.
This is well documented in spring documentation as can be seen from bellow.
According to doc
Spring Cloud Config Server
Spring Cloud Config Server provides an HTTP
resource-based API for external configuration (name-value pairs or
equivalent YAML content).
Also as documented about the serving format
Serving Alternative Formats
The default JSON format from the
environment endpoints is perfect for consumption by Spring
applications, because it maps directly onto the Environment
abstraction. If you prefer, you can consume the same data as YAML or
Java properties by adding a suffix (".yml", ".yaml" or ".properties")
to the resource path. This can be useful for consumption by
applications that do not care about the structure of the JSON
endpoints or the extra metadata they provide (for example, an
application that is not using Spring might benefit from the simplicity
of this approach).
It can also support txt format
Serving Plain Text
Instead of using the Environment abstraction (or
one of the alternative representations of it in YAML or properties
format), your applications might need generic plain-text configuration
files that are tailored to their environment.
But considering that spring cloud config server has the built in mechanism to communicate with a git repository and also exposes endpoints to the clients to consume the delivered files, it would make sense for other type of files to be able to be served from those endpoints as well.
It could be for example .pdf , .xslx , or even .zip
For example let's assume that the configured git repository contains the file myFile.zip in featureA branch. Then the call under the exposed path of type /{application}/{profile}[/{label}] for example as
serverUrl:serverPort/myApp/default/featureA/myFile.zip is able to deliver the file but is always delivered as raw .txt file which then corrupts the content of the original file existing in git.
I have already found the solution, but invested many hours on it and it was strange that it was not documented in spring documentation. So it is probably good to exist here as well to spare some time from others having the same issue.
As discussed under this issue, spring-cloud-config-server runs under the hood with the help of a normal spring-boot app. Considering that spring-boot has built in content negotiation mechanism it is able to consume and produce different content as well.
As for spring-cloud-config-server it is possible to fetch binary files from git as well as other files (ex zip, pdf, word, xlsx ...) if the call is made with the header Accept: application/octet-stream . This way the call to serverUrl:serverPort/myApp/default/featureA/myFile.zip is able to deliver a copy of the original file myFile.zip without any corruption.

Spring cloud config fails to pick configuration from local file system

I am trying to setup spring cloud config using local file system. However, I couldn't get it working.
Below is my application.properties file:
spring.application.name=spring-cloud-config-servers
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config
Inside limits-service.properties, I have the following:
limits-service.minimum=4
limits-service.maximum=400
Once i run the server, i get the following. Please help in fixing it.
It might be a simple mistake of naming?
For example, your spring application name is "limit-service" while your property files are named "limits-service" and that might be why it is not reading them.
yes above one it is working, spring.applicatiom.name must be equals to the properties file(Lets say uppercase must follow uppercase of properties file as well )

How can I set isolation-level-for-create via yaml configuration file for spring batch

I found a solution to do it via Java code here:
https://docs.spring.io/spring-batch/docs/4.2.x/reference/html/job.html#configuringJobRepository
But, I want to do it if possible in a simple way via configuration in yaml format in the batch configuration file.
Thank you.
As far as I know, there is currently no such property in yaml available.
There is an open feature request in Spring Boot (https://github.com/spring-projects/spring-boot/issues/28802) that may result in a property like spring.batch.jdbc.isolation-level-for-create in the future. Until then, you'll need to use Java (or XML) configuration.

Spring Cloud Config with HOCON files

I have configuration files which are in HOCON (.conf) format. I would like to use Spring Cloud Config to fetch them from a BitBucket repo, and send them to an application (which is NOT a Spring application) when it boots.
I am using the "Serving Plain Text" feature of Spring Cloud Config to fetch and serve a single HOCON file, which defines a particular environment. For example, the client application requests the development.conf environment configuration file, and by specifiying it's exact path in the BitBucket repo, say myApp/development/master/development.conf, the client is served that plaintext file.
However, as is usually desired, I would like base properties from the base.conf to be included in development.conf and have values overridden by the dev enviroment property values if there are common properties in both files.
Previously there was no config server, and so by simply writing the include "base" command at the top of the development.conf file, a HOCON parser (part of the TypeSafe library) in the client app requested the base.conf file (both files being in local directories), and did the overriding when necessary.
When including a Spring Config server, development.conf can be fetched in plain text as mentioned, but it is only (as before) at the client side that the application parses the include "base" command and then refetches the base.conf file. This makes the boot phase of the app very slow (probably) because fetching the additional files requires additional authorization on BitBucket.
Question: how to make it faster?
I have tried spring.cloud.config.server.git.cloneOnStart: true, but this has apparently no improvement (maybe I'm using it incorrectly?)
Should I consider converting the .conf format to .properties format, and using spring.profiles.include: base property at the top of the new developement.properties file?
Perhaps embed the Spring server in another Spring Boot application?
I like the property overriding and inclusion feature of Spring Cloud. I just don't know how to make it work with HOCON formatted files.

spring boot config server properties files under different folders?

Does anybody knows if we can store the properties file under different folders on github and then spring-boot config server can read those files?
for example if my repository for properties file is:
https://github.com/chetankokil/configfiles
Can i have as many folder as i want under config-files repository and then these folders will have properties files under it? Can it be done?
I would suggest to take a look at Spring Could Config module. Spring ecosystem has your use case covered and it's better to follow proven footsteps rather than creating your custom solution.
You can create various directories in Github and provide bootstrap.properties file in your project. A sample bootstrap file is shown below
spring.cloud.config.uri=<your config server url>
spring.application.name=<your folder name in github>
spring.cloud.config.label=<github project branch name>
spring.output.ansi.enabled=ALWAYS
spring.profiles.active=<active profile in spring>

Resources