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)
Related
Is there any way by chance to make spring config server to clone only specific path instead of whole git repo? When I'm running it on production I may not want my entire code base repository to be cloned to some location as it is always a risk. I've done my research and couldn't figure out ways to clone only specific paths of git repo.
One solution is to host the configurations in a seperate repo. But that would defeat the purpose of one code many deploys suggestion of 12factor.net.
Another possibility is to copy the properties into config server's classpath and then to use native profile to load them. But this would defeat the purpose of Spring ConfigServer.
Also kindly do clarify What would be the best way to run spring config server on a production?
You should be separating your code base from your configuration settings.
Repo 1: Your App Code
Repo 2: Your Spring Cloud Config Server Code
Repo 3: Your configuration settings
When you're deploying, you're deploying the code. Not the configuration. A configuration change should not require a new deployment. A new deployment might require an updated configuration change, but the two are generally decoupled.
Configuration can be dynamically updated while code is running. This is completely separate from updating code and deploying the app. That's the whole point of externalized configuration.
TL;DR: You're looking at "one code many deploys" wrong. Configuration is externalized.
I took this straight from 12factor.net
Apps sometimes store config as constants in the code. This is a violation of twelve-factor, which requires strict separation of config from code. Config varies substantially across deploys, code does not.
Even though you are no longer storing them as constants but still in the same repository is not enough separation from the code. Use a separate repository for configurations.
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?
I'm starting to use Spring Cloud Config and would like to give a way for clients to override properties that come from cofnig server. However, after reading https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html, it isn't apparent when the Cloud Configuration applies.
I've also read http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html and it talks about overrides. But they seem to be the opposite of what I want (those overrides are for overriding the client provided properties).
So, where does the Cloud Config fit in the ordering? Would I still be able to give a local application.properties file on the classpath to override certain Cloud Config properties?
The git commit/push process is part of the process, actually...Spring Cloud Config uses git to handle the config files, changes, auditing, etc., as git is ideally suited for that, & Config leverages those strengths.
If you're just looking for a way to expedite testing of config changes and are willing to accept the tradeoffs, you can use a local (or local network) repo for your config repository for testing. I realize this isn't what you're asking specifically, but it's an option that may help, assuming you're using the Config server app's application.properties to point to the underlying git repo. If so, you can override spring.cloud.config.server.git.uri on the command line like so:
java -Dspring.cloud.config.server.git.uri=${HOME}/testing/config-repo -jar your_jar_here.jar
This will allow you to tweak the config settings for client apps/services that obtain their settings from the Config server without affecting the production config files (even branches).
I hope this helps. If not, or if I've misunderstood your goals or constraints, please clarify (a use case or two might help me triangulate better, if you can share them) and I'll take another run at it. :)
Cheers,
Mark
I have externalized all my application needed property files from webapps in tomcat. Now i can simply change a property file value without a need of rebuilding the war file and deploy it again. However each change to property file is associated with server recyling.
Is there a way how the recycling can be avoided for a property file change.
I am using spring to read the property files for few webapps and java property traditional way for few webapps.
Please suggest how to acheive
You may want to consider spring-cloud-config-server or spring-cloud-consul all of these options supports distributed properties management as well as value changes refresh without a need to recycle app servers.
And you can use #RefreshScope for Spring #Beans that want to be reinitialized when configuration changes, they also provide the following Management endpoints out of the box and many more as explained on the project git page
/refresh for refreshing the #RefreshScope beans
/restart for restarting the Spring context (disabled by default)
This is supported by either option (spring-cloud-config-server or spring-cloud-consul)
You may also give cfg4j a try. It supports reloading configuration from local files as well as remote services (git repository, Consul, etc.).
I'm using Spring 2.5.6. I have a bean whose properties are being assign from a property file via a PropertyPlaceholderConfigurer. I'm wondering whether its possible to have the property of the bean updated when the property file is modified. There would be for example some periodic process which checks the last modified date of the property file, and if it has changed, reload the bean.
I'm wondering if there is already something that satisfies my requirements. If not, what would be the best approach to solving this problem?
Thanks for your help.
Might also look into useing Spring's PropertyOverrideConfigurer. Could re-read the properties and re-apply it in some polling/schedular bean.
It does depend on how the actual configured beans use these properties. They might, for example, indirectly cache them somewhere themself.
If you want dynamic properties at runtime, perhaps another way to do it is JMX.
One way to do this is to embed a groovy console in your application. Here's some instructions. They were very simple to do, btw - took me very little time even though I'm not that familiar with groovy.
Once you do that you can simply go into the console and change values inside the live application on the fly.
You might try to use a custom scope for the bean that recreates beans on changes of the properties file. See my more extensive answer here.
Spring Cloud Config has facilities to change configuration properties at runtime via the Spring Cloud Bus and using a Cloud Config Server. The configuration or .properties or .yml files are "externalized" from the Spring app and instead retrieved from a Spring Cloud Config Server that the app connects to on startup. That Cloud Config Server retrieves the appropriate configuration .properties or .yml files from a GIT repo (there are other storage solutions, but GIT is the most common). You can then change configuration at runtime by changing the contents of the GIT repo's configuration files--The Cloud Config Server broadcasts the changes to any Client Spring applications via the Spring Cloud Bus, and those applications' configuration is updated without needing a restart of the app. You can find a working simple example here: https://github.com/ldojo/spring-cloud-config-examples