spring boot config server properties files under different folders? - spring

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>

Related

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 )

UI base config for spring boot

I have a centralized configuration for spring boot service. I followed this link to make it.
I have configServer and configs two separate project. Configs have several properties files. And configServer reading it and rendering to other services.
Now I want to make configs UI based.
e.g.
application.properties of configs which is hosted at git.
logging.path=logs
logging.level.root=INFO
logging.level.org.springframework.boot.autoconfigure.security=INFO
It`s UI should be
logging.path as key text box for value( logs ).
Is there any example for it. Any help will be appreciated.
Thanks.
Since you mention using text box in your post, I'm assuming that by UI you mean GUI.
While I'm not aware of any examples (and you do not specify whether you want to have a destktop or web application) if you're using git to store configuration, your app needs to:
Checkout the git repo with configuration (using JGit for example)
Load properties files generate edit window for each file (something
similar to what IntelliJ does for environment variables in run
configurations perhaps)
Save edits to files
Commit and push changes (again using JGit or a similar library)

Get all config files with spring cloud config

I am relatively new to spring cloud config and I am able to pull the config file with the application name. There is a need for me to pull all the config files from Git via Spring Cloud Config without having to know or pass the application name in the context.
Currently I have used "spring.cloud.config.server.git.searchPaths= *" in my bootstrap file to search my entire git project and using "/{application}-{profile}.properties" to pull the properties files matching the application file. Would want to pull all properties files without passing this application name, is this possible?
I would require this logic to know how many properties files are checked in and how many are duplicates and this logic will be handled by my custom REST service that I am planning to write.

Multiple External Configuration Sprintg boot

I am using Springboot and developing web services based on those. In my services, I am keeping the configuration at git instead of with project, so that I will be able to change the properties at run-time without restarting the application.
I am using a ConfigServer to fetch the configuartion and all my services are Config Client.
But the issue is my config files are fetched from git based on
-.properties file, so for ex. if my application name is demo and active profile is testing, then the config file which is getting fetched from git is demo-testing.properties.
But the issue I want to have more than one config file. So how should I mention second config file?
Also the second config file is common to other services also?
So actually I want to use same config file for many services which is located at git?

What is the best place to store the application.properties file for a Spring boot application?

I have an application.properties file which I have placed at the same level as the src folder. Things are working correctly. But, is this the standard place to keep this file? What is the best practice?
I place them at src/main/resources. Some would prefer src/main/resources/config. When deploying, I put the customized properties at the same folder where the jar is placed. Again, some would prefer the config sub folder.
Spring Boot picks the files from these locations by default.
Under src folder create another folder named config let's say. Here create another folder named local. Than place your file here. This structure is used when you want to deploy to different servers(i.e. local, test, live).
Then you can create profiles and for example you can configure Maven to choose the proper application.properties file located in one of these folders to create the war and deploy.
So have something live config/local/application.properties and at least config/live/application.properties
UPDATE
What IDE are you using? You need to declare the path as a resource path. See how to do that depending on what you are developing. At build time, the path need to contain some resources, i.e. one or more folders in which the .properties files will be placed.
You can also try the path sugested in another answers src/main/resources (it is more explicit I agree) but the thing is that you can place your resources anywhere but you need to declare the location as a resource location.

Resources