Springboot- reload property values without server restart - spring

I have a springboot application and an application.properties file from which the values get fetched when the application runs. I am finding a solution to change the property values and reload it without server restart.
Using spring-cloud-config is a solution I know, but I cant use the cloud config in our application . Please suggest if there is any other way to reload the property files using springboot.

You can use archaius available at https://github.com/Netflix/archaius.
Here is how you use it.
DynamicStringProperty property = getDynamicPropertyFactoryInstance()
.getStringProperty(key, StringUtils.EMPTY);
You will have to create a wrapper now to read all values from config.properties file. Archaius reads and returns updated values from config.properties file by default.

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 )

How to specify vault endpoint In springboot vault configuration without application name

In spring boot I wanted to read the properties from vault but I wanted to read vaulr secret token and the full path of the configuration endpoint from environment variable.
But if I give spring.cloud.vault.uri it is not working and for fetching from environmental variable I am using ${VAULT_TOKEN} but this also, not working.
spring.cloud.vault.uri=http://127.0.0.1:8200/secret/gs-vault-config/cloud/test
spring.cloud.vault.token=${VAULT_TOKEN}
I wanted to fetch both spring.cloud.vault.uri and spring.cloud.vault.token from environmental variable.
It's not a good idea.
Usually the file bootstrap.properties/bootstrap.yaml is placed separately from the project (project in /src, bootstrap config file in /config). It allows us to use it without rebuilding the project on parameter changes, and to use a dynamic configuration.
We already have a file with dynamic content, you want to create a separate dynamic config file with values for base dynamic config file! Tautology!

properties file reload on change in server, Spring

i am using Spring 4.2.5 and jboss 7 server.
Is it possible to change in application.properties files and make server to reload changed data in application.properties file automatically on refresh without restarting server?
Please suggest on this. Any idea or steps or api to use anything to move forward.
Regards
Ideal way would be use spring cloud config
#EnableConfigServer. You will have separate config server pointed all the properties pointed. And a client will be able to access the properties. This allows you to change the properties on the fly in server with out need for any restart.
http://jeroenbellen.ghost.io/manage-and-reload-spring-application-properties-on-the-fly/

Properties change with out a server restart

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.).

Having spring bean properties refreshed automatically from properties file

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

Resources