Spring boot - how to modify config properties from an external application - spring

I have a spring boot application and it has an application.yml file that contains a bunch of properties. I am writing a separate test harness for this application and using that application I would like to modify some properties after the main application starts up. I am thinking that I need to add a new REST endpoint that will implement the PUT method and will change the properties. Using that PUT method I should be able to change any property that is defined in the application.yml file. Is that the correct approach. Is there a sample application that I can take a look at.

Related

Spring Boot add properties on top of current default properties

I am working with a spring boot application, in that application there is a config to set spring active profile:
{Library}/bootstrap.properties
spring.profiles.active=standalone
Let say I want to add on top of the above config, so it becomes
{My App}/bootstrap.properties (What I current can do)
spring.profiles.active=standalone,myprofile
But I don't want to specified standalone, I want to specified the default properties from the library (i.e. default active profiles from the library) so I can make sure my property is future proofed.
So I want something like this:
{My App}/bootstrap.properties (What I want to achieve)
spring.profiles.active={Library spring.profiles.active},myprofile
And {Library spring.profiles.active} in the above will translate to standalone
Any method the achieve the above? Thanks.

Use External properties file

Am looking to pass variables at run time once war file is deployed on tomcat ..
How can i use application.properties whcih is in classplath along with another properties file ex. abcd.properties located at particular directory..Am basically looking to set additional classpath and read value from properties file in that path along with default classpath location for war deployment.
Am using Spring boot .One of the way is to pass all properties to database end , but am looking for a file based i.e properties based workout.
(Having multiple applications on same tomcat instance.)
Spring Boot App --> run as --> run configurations. Now here in VM arguments add Dproperties.location="Path of the properties".
Now, in your Spring Boot application use the annotation #PropertySource("file:${properties.location}/propertiesfileName.properties") just above the class declaration.
Autowire Environment in your class. use env.getProperty("propertyname").
You can access the values from application.properties as usual using #Value annotation. Hope this helps.

How to change and reload application configuration using a jax-rs service

I have to provide the user of my application, a resource end point with which he should be able to configure the application properties. The property class should be singleton. How can I achieve this. I am using springboot.
What I tried:
I did some reading on actuators, but it seems to work on application.properties,
but I need to use a rest service to configure the properties.

How to make Spring Boot skipping some configurations

I have a Spring-Boot project which works with DB-connections and a lot of other stuff.
Now I added another "main-class" to the project. The thing is: by starting this class, all configuration settings (which come from application.yml) are loaded. But thats not what I want.
I want the project to start without trying to bind to any datasource...
But how?
Why do you add several main classes? Try using different profiles instead. And you can start your application with the -Dspring.profiles.active=? property.
Example:
Just add a application-test.properties and run your application with -Dspring-profiles.active=test and the properties in the test property file will be loaded. And potentially overwrite properties with the same key in application.properties.

Spring cloud config server - more than 1 properties file per app

Does anybody knows if it is possible to expose more than 1 property file per application in Spring Cloud config server?
For example I would like to have defined in my git repo properties for the same app, but in different files:
myapp-customer-services.yml
myapp-products-services.yml
and have all those properties defined inside the files, exposed under "myapp".
No that's not possible currently. I'm not sure it really makes much sense to be honest, since you can easily clearly delineate different sets of properties within a YAML file using separate documents.
Yes it is possible to expose more than 1 property file per application in Spring Cloud config server
You can access it in you client by using following properties
first specify profile which you want
example
myapp-customer.yml
myapp-products.yml
spring.profiles.active=customer,products
spring.cloud.config.name=myapp

Resources