Replace property file in spring boot application - spring

I tried searching couple of posts/articles/forum but seems my questions is still unanswered. I am looking for a way in spring boot to replace application property based on some flag. Here is is what i am trying to do :
I have file called products.properties in spring boot application where in my application properties are defined.
I also have file called products.properties.replace which replaces based on environment like QA,Dev all property values.
Now i want two replace file because i have two types of server whose values will be different & replace file already have environment based values.
Can we have multiple replace files & by environment variable can i make that replace file picked by spring application.

Related

Spring properties inside library

So I've got a library which contains default things like authentication and stuff like that, which are all equal across multiple applications.
I'd like to have an application.properties inside the library setting up some default values. But at the same time I would like the actual application to be able to overwrite these library values inside the applications' properties file.
But I can't seem to figure out how to get spring to read the librarys' property file.

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.

Environment specific properties from user home in springboot

I am working on a spring boot application in which i have to set Environment specific properties from user home folder.
i dig Google for the same & found we can put different properties file (dev, test, production) under resources and then we have to tell spring boot which environment we want to use using spring.profiles.active=dev OR prod.
however, my requirement is quite different. i will put a file in user home in my system & want to read properties form that file. how can i do that, need guidance.
Helping hands will be highly appreciated.
From the Spring Boot docs:
You can also refer to an explicit location using the spring.config.location environment property (comma-separated list of directory locations, or file paths).
As the docs go on to state, this must be specified on the command line or as an environment variable.
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
We explain that use case in a Devoxx presentation using EnvironmentPostProcessor, please refer to this section of the presentation for more details. You can also find the code sample online.
Well, it seems in your case you dont need environment variable. For production server your property file will be staying in and in staging machine it is also staying at same place. So where ever you deploy it will pick from . IMO you don't need to set environment, you just have to point property file to
Now to define this path you have 2 ways..
- You can put static path in your code
- You can set environment variable like Property_Path and read it in spring boot application..
However If you want to go one step ahead, you can use spring cloud configuration manager, by passing application+profile name to it, CM can fetch property file from directly from git or file system for you ...

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

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.

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